/** * The Angular platform is the entry point for Angular on a web page. * Each page has exactly one platform. Services (such as reflection) which are common * to every Angular application running on the page are bound in its scope. * A page's platform is initialized implicitly when a platform is created using a platform * factory such as `PlatformBrowser`, or explicitly by calling the `createPlatform()` function. * * @publicApi */ exportdeclareclassPlatformRef { private _injector; private _modules; private _destroyListeners; private _destroyed; /** * Creates an instance of an `@NgModule` for the given platform. * * @deprecated Passing NgModule factories as the `PlatformRef.bootstrapModuleFactory` function * argument is deprecated. Use the `PlatformRef.bootstrapModule` API instead. */ bootstrapModuleFactory<M>( moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions ): Promise<NgModuleRef<M>>; /** * Creates an instance of an `@NgModule` for a given platform. * * @usageNotes * ### Simple Example * * ```typescript * @NgModule({ * imports: [BrowserModule] * }) * class MyModule {} * * let moduleRef = platformBrowser().bootstrapModule(MyModule); * ``` * */ bootstrapModule<M>( moduleType: Type<M>, compilerOptions?: | (CompilerOptions & BootstrapOptions) | Array<CompilerOptions & BootstrapOptions> ): Promise<NgModuleRef<M>>; private _moduleDoBootstrap; /** * Registers a listener to be called when the platform is destroyed. */ onDestroy(callback: () =>void): void; /** * Retrieves the platform {@link Injector}, which is the parent injector for * every Angular application on the page and provides singleton providers. */ getinjector(): Injector; /** * Destroys the current Angular platform and all Angular applications on the page. * Destroys all modules and listeners registered with the platform. */ destroy(): void; getdestroyed(): boolean; static ɵfac: i0.ɵɵFactoryDeclaration<PlatformRef, never>; static ɵprov: i0.ɵɵInjectableDeclaration<PlatformRef>; }
// All of the logic below is irrelevant for AOT-compiled code. if (typeof ngJitMode !== "undefined" && !ngJitMode) { returnPromise.resolve(moduleFactory); }
// Configure the compiler to use the provided options. This call may fail when multiple modules // are bootstrapped with incompatible options, as a component can only be compiled according to // a single set of options. setJitOptions({ defaultEncapsulation: _lastDefined( compilerOptions.map((opts) => opts.defaultEncapsulation) ), preserveWhitespaces: _lastDefined( compilerOptions.map((opts) => opts.preserveWhitespaces) ), });
if (isComponentResourceResolutionQueueEmpty()) { returnPromise.resolve(moduleFactory); }
// In case there are no compiler providers, we just return the module factory as // there won't be any resource loader. This can happen with Ivy, because AOT compiled // modules can be still passed through "bootstrapModule". In that case we shouldn't // unnecessarily require the JIT compiler. if (compilerProviders.length === 0) { returnPromise.resolve(moduleFactory); }
const compiler = getCompilerFacade({ usage: JitCompilerUsage.Decorator, kind: "NgModule", type: moduleType, }); const compilerInjector = Injector.create({ providers: compilerProviders }); const resourceLoader = compilerInjector.get(compiler.ResourceLoader); // The resource loader can also return a string while the "resolveComponentResources" // always expects a promise. Therefore we need to wrap the returned value in a promise. returnresolveComponentResources((url) => Promise.resolve(resourceLoader.get(url)) ).then(() => moduleFactory); }
// We need to resolve the injector types separately from the injector creation, because // the module might be trying to use this ref in its constructor for DI which will cause a // circular error that will eventually error out, because the injector isn't created yet. this._r3Injector._resolveInjectorDefTypes(); this.instance = this.get(ngModuleType); }