• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.ReflectiveInjector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.Renderer类代码示例发布时间:2022-05-25
下一篇:
TypeScript core.QueryList类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap