當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.PlatformRef類代碼示例

本文整理匯總了TypeScript中@angular/core.PlatformRef的典型用法代碼示例。如果您正苦於以下問題:TypeScript PlatformRef類的具體用法?TypeScript PlatformRef怎麽用?TypeScript PlatformRef使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PlatformRef類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: bootstrap

export function bootstrap(platform: PlatformRef, Ng2Module: Type<{}>, element: Element, modules: string[]) {
  // We bootstrap the Angular module first; then when it is ready (async)
  // We bootstrap the AngularJS module on the bootstrap element
  return platform.bootstrapModule(Ng2Module).then(ref => {
    const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(element, modules);
    return upgrade;
  });
}
開發者ID:jtk54,項目名稱:deck,代碼行數:9,代碼來源:helpers.ts

示例2: bootstrap

export function bootstrap(
    platform: PlatformRef, Ng2Module: Type<{}>, element: Element, ng1Module: angular.IModule) {
  // We bootstrap the Angular 2 module first; then when it is ready (async)
  // We bootstrap the Angular 1 module on the bootstrap element
  return platform.bootstrapModule(Ng2Module).then(ref => {
    var upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(element, [ng1Module.name]);
    return upgrade;
  });
}
開發者ID:efidiles,項目名稱:angular,代碼行數:10,代碼來源:test_helpers.ts

示例3: bootstrap

export function bootstrap(
    platform: PlatformRef, Ng2Module: Type<{}>, element: Element, ng1Module: angular.IModule) {
  // We bootstrap the Angular module first; then when it is ready (async) we bootstrap the AngularJS
  // module on the bootstrap element (also ensuring that AngularJS errors will fail the test).
  return platform.bootstrapModule(Ng2Module).then(ref => {
    const upgrade = ref.injector.get(UpgradeModule);
    const failHardModule: any = ($provide: angular.IProvideService) => {
      $provide.value('$exceptionHandler', (err: any) => { throw err; });
    };
    upgrade.bootstrap(element, [failHardModule, ng1Module.name]);
    return upgrade;
  });
}
開發者ID:DanielKucal,項目名稱:angular,代碼行數:13,代碼來源:test_helpers.ts

示例4: bootstrap

export function bootstrap(
    platform: PlatformRef, Ng2Module: Type<{}>, element: Element, ng1Module: angular.IModule) {
  // We bootstrap the Angular module first; then when it is ready (async) we bootstrap the AngularJS
  // module on the bootstrap element (also ensuring that AngularJS errors will fail the test).
  return platform.bootstrapModule(Ng2Module).then(ref => {
    const ngZone = ref.injector.get<NgZone>(NgZone);
    const upgrade = ref.injector.get(UpgradeModule);
    const failHardModule: any = ($provide: angular.IProvideService) => {
      $provide.value($EXCEPTION_HANDLER, (err: any) => { throw err; });
    };

    // The `bootstrap()` helper is used for convenience in tests, so that we don't have to inject
    // and call `upgrade.bootstrap()` on every Angular module.
    // In order to closer emulate what happens in real application, ensure AngularJS is bootstrapped
    // inside the Angular zone.
    //
    ngZone.run(() => upgrade.bootstrap(element, [failHardModule, ng1Module.name]));

    return upgrade;
  });
}
開發者ID:cyrilletuzi,項目名稱:angular,代碼行數:21,代碼來源:test_helpers.ts

示例5: describe

describe('angularfire', () => {
  let subscription:Subscription;
  let app: FirebaseApp;
  let rootRef: firebase.database.Reference;
  let questionsRef: firebase.database.Reference;
  let listOfQuestionsRef: firebase.database.Reference;
  let defaultPlatform: PlatformRef;

  const APP_NAME = 'super-awesome-test-firebase-app-name';

  beforeEach(() => {

    TestBed.configureTestingModule({
      imports: [AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME)]
    });

    inject([FirebaseApp, PlatformRef], (_app: FirebaseApp, _platform: PlatformRef) => {
      app = _app;
      rootRef = app.database().ref();
      questionsRef = rootRef.child('questions');
      listOfQuestionsRef = rootRef.child('list-of-questions');
      defaultPlatform = _platform;
    })();

  });

  afterEach((done) => {
    rootRef.remove()
    if(subscription && !subscription.closed) {
      subscription.unsubscribe();
    }
    app.delete().then(done, done.fail);
  });

  describe('FirebaseApp', () => {
    it('should provide a FirebaseApp for the FirebaseApp binding', () => {
      expect(typeof app.delete).toBe('function');
    });
    it('should have the provided name', () => {
      expect(app.name).toBe(APP_NAME);
    })
    it('should use an already intialized firebase app if it exists', done => {
      @NgModule({
        imports: [
          AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME),
          BrowserModule
        ]})
      class MyModule {
        ngDoBootstrap() {}
      }

      const compilerFactory: CompilerFactory =
          defaultPlatform.injector.get(CompilerFactory, null);
      const moduleFactory = compilerFactory.createCompiler().compileModuleSync(MyModule);

      defaultPlatform.bootstrapModuleFactory(moduleFactory)
        .then(moduleRef => {
          const ref = moduleRef.injector.get(FirebaseApp);
          expect(ref.name).toEqual(app.name);
        }).then(done, e => {
          fail(e);
          done()
        });
    })
  });
});
開發者ID:cartant,項目名稱:angularfire2,代碼行數:66,代碼來源:angularfire2.spec.ts

示例6: async

  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;

    }
  })
開發者ID:Urigo,項目名稱:angular-meteor,代碼行數:91,代碼來源:main.ts

示例7: callback

        .then(() => {
          const platformState = platform.injector.get(PlatformState);

          // Run any BEFORE_APP_SERIALIZED callbacks just before rendering to string.
          const callbacks = moduleRef.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 output = platformState.renderToString();
          platform.destroy();
          return output;
        });
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:20,代碼來源:utils.ts

示例8: it

    it('should use an already intialized firebase app if it exists', done => {
      @NgModule({
        imports: [
          AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME),
          BrowserModule
        ]})
      class MyModule {
        ngDoBootstrap() {}
      }

      const compilerFactory: CompilerFactory =
          defaultPlatform.injector.get(CompilerFactory, null);
      const moduleFactory = compilerFactory.createCompiler().compileModuleSync(MyModule);

      defaultPlatform.bootstrapModuleFactory(moduleFactory)
        .then(moduleRef => {
          const ref = moduleRef.injector.get(FirebaseApp);
          expect(ref.name).toEqual(app.name);
        }).then(done, e => {
          fail(e);
          done()
        });
    })
開發者ID:cartant,項目名稱:angularfire2,代碼行數:23,代碼來源:angularfire2.spec.ts

示例9:

 .then(() => {
   const output = platform.injector.get(PlatformState).renderToString();
   platform.destroy();
   return output;
 });
開發者ID:mdegani,項目名稱:angular,代碼行數:5,代碼來源:utils.ts

示例10:

 const complete = () => {
   const output = platformState.renderToString();
   platform.destroy();
   return output;
 };
開發者ID:Cammisuli,項目名稱:angular,代碼行數:5,代碼來源:utils.ts


注:本文中的@angular/core.PlatformRef類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。