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


TypeScript core.ReflectiveInjector類代碼示例

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


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

示例1: useInjector

export function useInjector() {
  var injector:ReflectiveInjector;

//#enddocregion injector
/*
//#docregion injector-no-new
  // Cannot 'new' an ReflectiveInjector like this!
  var injector = new ReflectiveInjector([Car, Engine, Tires, Logger]);
//#enddocregion injector-no-new
*/

//#docregion injector
  //#docregion injector-create-and-call
  injector = ReflectiveInjector.resolveAndCreate([Car, Engine, Tires, Logger]);
  //#docregion injector-call
  var car = injector.get(Car);
 //#enddocregion injector-call
 //#enddocregion injector-create-and-call
  car.description = 'Injector';

  var logger = injector.get(Logger);
  logger.log('Injector car.drive() said: '+car.drive());

  return car;
}
開發者ID:Brocco,項目名稱:angular.io,代碼行數:25,代碼來源:car-injector.ts

示例2: beforeEach

    beforeEach(() => {
      mockRouterProvider = new MockRouterProvider();

      injector = ReflectiveInjector.resolveAndCreate([
        ViewContainerRef,
        MessageService,
        DynamicComponentLoader,
        provide(APP_CONFIG, {useValue: CONFIG}),
        provide(NavigationHistoryService, {useClass: MockNavigationHistoryService}),
        provide(LocalStorageService, {useClass: MockLocalStorageService}),
        mockRouterProvider.getProviders()
      ]);

      routerOutlet = new CetAuthRouterOutletDirective(
        injector.get(ViewContainerRef), injector.get(DynamicComponentLoader),
        injector.get(Router), '',
        injector.get(LocalStorageService), injector.get(MessageService),
        injector.get(NavigationHistoryService), injector.get(APP_CONFIG)
      );

      instruction = new ComponentInstruction();

      routerOutlet.config.routeName = {
        login: 'Login',
        dashboard: 'Dashboard'
      };

      spyOn(routerOutlet.parentRouter, 'navigate');
      spyOn(routerOutlet.historyService, 'push');
      spyOn(routerOutlet.messageService, 'publish');
      spyOn(routerOutlet.historyService, 'isHomePage');
      spyOn(RouterOutlet.prototype, 'activate');
    });
開發者ID:AdamFaron,項目名稱:FOO,代碼行數:33,代碼來源:cetAuthRouterOutlet.directive.spec.ts

示例3: beforeEach

    beforeEach(() => {
      //mock providers
      let injector: ReflectiveInjector = ReflectiveInjector.resolveAndCreate([
        PopupService
      ]);

      popup  = injector.get(PopupService);
    });
開發者ID:AdamFaron,項目名稱:FOO,代碼行數:8,代碼來源:popup.service.spec.ts

示例4: beforeEach

    beforeEach(() => {
      let injector: ReflectiveInjector = ReflectiveInjector.resolveAndCreate([
        HTTP_PROVIDERS,
        HttpService,
        TokenService,
        LocalStorageService,
        PopupService,
        provide(APP_CONFIG, {useValue: CONFIG})
      ]);

      tokenService = injector.get(TokenService);
      config = injector.get(APP_CONFIG);
    });
開發者ID:AdamFaron,項目名稱:FOO,代碼行數:13,代碼來源:token.service.spec.ts

示例5: beforeEach

  beforeEach(() => {
    spyOn(Reducer, 'reduce').and.callThrough();
    spyOn(Middleware, 'pre').and.callThrough();
    spyOn(Middleware, 'post').and.callThrough();

    injector = ReflectiveInjector.resolveAndCreate([
      provideStore(Reducer.reduce, initialState),
      usePreMiddleware(Middleware.pre),
      usePostMiddleware(Middleware.post)
    ]);

    backend = injector.get(StoreBackend);
    dispatcher = injector.get(Dispatcher);
  });
開發者ID:dsebastien,項目名稱:store,代碼行數:14,代碼來源:backend_spec.ts

示例6: makeRouter

 function makeRouter(baseHref: string = '/my/app', provider: any = CONST_EXPR([])): Router {
   locationStrategy = new MockLocationStrategy();
   locationStrategy.internalBaseHref = baseHref;
   let injector = ReflectiveInjector.resolveAndCreate(
       [Router, provide(LocationStrategy, {useValue: locationStrategy}), provider]);
   return router = injector.get(Router);
 }
開發者ID:MikeRyan52,項目名稱:router,代碼行數:7,代碼來源:router.spec.ts

示例7: it

        it('should be able to provide any TranslateLoader', () => {
            class CustomLoader implements TranslateLoader {
                getTranslation(lang: string): Observable<any> {
                    return Observable.of({"TEST": "This is a test"});
                }
            }
            injector = ReflectiveInjector.resolveAndCreate([
                HTTP_PROVIDERS,
                // Provide a mocked (fake) backend for Http
                provide(XHRBackend, {useClass: MockBackend}),
                TRANSLATE_PROVIDERS,
                provide(TranslateLoader, {useClass: CustomLoader})
            ]);
            prepare(injector);

            expect(translate).toBeDefined();
            expect(translate.currentLoader).toBeDefined();
            expect(translate.currentLoader instanceof CustomLoader).toBeTruthy();

            // the lang to use, if the lang isn't available, it will use the current loader to get them
            translate.use('en');

            // this will request the translation from the CustomLoader
            translate.get('TEST').subscribe((res: string) => {
                expect(res).toEqual('This is a test');
            });
        });
開發者ID:DanielKucal,項目名稱:ng2-translate,代碼行數:27,代碼來源:translate.service.spec.ts

示例8: beforeEach

  beforeEach(function() {
    mockTraverser = {
      find() {
        return Observable.of({ routes, params });
      }
    };

    mockZone = {
      run(fn) {
        return fn();
      }
    };

    spyOn(mockTraverser, 'find').and.callThrough();
    spyOn(mockZone, 'run').and.callThrough();

    const injector = ReflectiveInjector.resolveAndCreate([
      ROUTER_PROVIDERS,
      ROUTE_SET_PROVIDERS,
      provide(RouteTraverser, { useValue: mockTraverser }),
      provide(LocationStrategy, { useClass: MockLocationStrategy }),
      provide(NgZone, { useValue: mockZone })
    ]);

    routerInstruction = injector.get(RouterInstruction);
    router = injector.get(Router);
  });
開發者ID:MikeRyan52,項目名稱:router,代碼行數:27,代碼來源:router-instruction.spec.ts

示例9: it

  it('should allow you to compose middleware using providers', function() {
    const testToken = new OpaqueToken('Test Token');
    const middlewareProvider = provideMiddlewareForToken(testToken);

    const first = { apply: t => t };
    const second = { apply: t => t };
    const third = { apply: t => t };

    spyOn(first, 'apply');
    spyOn(second, 'apply');
    spyOn(third, 'apply');

    const secondProvider = provide(new OpaqueToken('Second Midleware'), {
      useValue: second.apply
    });

    const thirdProvider = createMiddleware(() => third.apply);

    const injector = ReflectiveInjector.resolveAndCreate([
      middlewareProvider(first.apply, secondProvider, thirdProvider)
    ]);

    const middlewareArray = injector.get(testToken);
    compose(...middlewareArray)();

    expect(first.apply).toHaveBeenCalled();
    expect(second.apply).toHaveBeenCalled();
    expect(third.apply).toHaveBeenCalled();
  });
開發者ID:MikeRyan52,項目名稱:router,代碼行數:29,代碼來源:middleware.spec.ts

示例10: bootstrapRender

export function bootstrapRender(
    workerScriptUri: string,
    customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ApplicationRef> {
  var pf = ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM);
  var app = ReflectiveInjector.resolveAndCreate(
      [
        WORKER_RENDER_APPLICATION,
        /* @ts2dart_Provider */ {provide: WORKER_SCRIPT, useValue: workerScriptUri},
        isPresent(customProviders) ? customProviders : []
      ],
      workerRenderPlatform().injector);
  // Return a promise so that we keep the same semantics as Dart,
  // and we might want to wait for the app side to come up
  // in the future...
  return PromiseWrapper.resolve(app.get(ApplicationRef));
}
開發者ID:JavaScript-Resource,項目名稱:angular,代碼行數:16,代碼來源:worker_render.ts


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