import { enableProdMode } from '@angular/core'; import { bootstrap } from '@angular/platform-browser-dynamic'; import { HTTP_PROVIDERS } from '@angular/http'; import { AppComponent } from './app/app.component'; import { APP_ROUTER_PROVIDERS } from './app/app.routes'; // depending on the env mode, enable prod mode or add debugging modules if (process.env.ENV === 'build') { enableProdMode(); } bootstrap(AppComponent, [ // Array with dependiences of our application HTTP_PROVIDERS, APP_ROUTER_PROVIDERS ]) .catch(err => console.error(err));
import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; const platform = platformBrowserDynamic(); enableProdMode(); // Comment this line when in developer mode platform.bootstrapModule(AppModule);
import { APP_BASE_HREF } from '@angular/common'; import { disableDeprecatedForms, provideForms } from '@angular/forms'; import { enableProdMode } from '@angular/core'; import { bootstrap } from '@angular/platform-browser-dynamic'; import { APP_ROUTER_PROVIDERS } from './app.routes'; import { AppComponent } from './app.component'; if ('<%= ENV %>' === 'prod') { enableProdMode(); } //enableProdMode(); /** * Bootstraps the application and makes the ROUTER_PROVIDERS and the APP_BASE_HREF available to it. * @see https://angular.io/docs/ts/latest/api/platform-browser-dynamic/index/bootstrap-function.html */ bootstrap(AppComponent, [ disableDeprecatedForms(), provideForms(), APP_ROUTER_PROVIDERS, { provide: APP_BASE_HREF, useValue: '<%= APP_BASE %>' } ]); // In order to start the Service Worker located at "./worker.js" // uncomment this line. More about Service Workers here // https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers // // if ('serviceWorker' in navigator) {
Meteor.startup(() => { // Enable Angular's production mode if Meteor is in production mode if (Meteor.isProduction) { enableProdMode(); } // When page requested WebAppInternals.registerBoilerplateDataCallback('angular', async (request, data) => { let document, platformRef: PlatformRef; // Handle Angular's error, but do not prevent client bootstrap try { document = ` <html> <head> <base href="/"> </head> <body> <app></app> </body> </html> `; // Integrate Angular's router with Meteor const url = request.url; // Get rendered document platformRef = platformDynamicServer([ { provide: INITIAL_CONFIG, useValue: { // Initial document document, url } } ]); const appModuleRef = await platformRef.bootstrapModule(ServerAppModule, { ngZone: 'noop', providers: [ { provide: ResourceLoader, useValue: { get: Assets.getText }, deps: [] } ] }); const applicationRef: ApplicationRef = appModuleRef.injector.get(ApplicationRef); await applicationRef.isStable.pipe( first(isStable => isStable == true) ).toPromise(); applicationRef.tick(); // Run any BEFORE_APP_SERIALIZED callbacks just before rendering to string. const callbacks = appModuleRef.injector.get(BEFORE_APP_SERIALIZED, null); if (callbacks) { for (const callback of callbacks) { try { callback(); } catch (e) { // Ignore exceptions. console.warn('Ignoring BEFORE_APP_SERIALIZED Exception: ', e); } } } const platformState: PlatformState = appModuleRef.injector.get(PlatformState); document = platformState.renderToString(); } catch (e) { // Write errors to console console.error('Angular SSR Error: ' + e.stack || e); } finally { //Make sure platform is destroyed before rendering if (platformRef) { platformRef.destroy(); } const head = HEAD_REGEX.exec(document)[1]; data.dynamicHead = head; const body = BODY_REGEX.exec(document)[1]; data.dynamicBody = body; } }) });