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


TypeScript ReflectiveInjector.resolveAndCreate方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: exported

export function exported(
    modulePrefix = '',
    getGlobalInjector: () => Injector,
    aliases: {}
)
{
    const globalGet = function(token) {
        if (aliases.hasOwnProperty(token)) {
            token = aliases[token];
        }

        return getGlobalInjector().get(token);
    };

    if (modulePrefix.length > 0) {
        modulePrefix = modulePrefix + '.';
    }

    const localInjector = ReflectiveInjector.resolveAndCreate([
        provide('OtherService', {useFactory: () => { return globalGet('OtherService'); }, deps: [] }),
        PartA, PartB, ExampleService,
        Example
    ]);

    return [
        provide(modulePrefix + 'Module.Example', {useFactory: () => { return localInjector.get(Example); }, deps: []}),
    ];
}
開發者ID:gacek85,項目名稱:nodejs-typescript-angular2-boilerplate,代碼行數:28,代碼來源:di.ts

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: beforeEach

    beforeEach(() => {
      const rootInjector = ReflectiveInjector.resolveAndCreate([ Dispatcher, SagaRunner, schedulerProvider ]);
      const childInjector = rootInjector.resolveAndCreateChild([ SagaRunner ]);

      runner = rootInjector.get(SagaRunner);
      child = childInjector.get(SagaRunner);
      dispatcher = rootInjector.get(Dispatcher);
    });
開發者ID:fxck,項目名稱:store-saga,代碼行數:8,代碼來源:index.spec.ts

示例10: beforeEach

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

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


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