当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ReflectiveInjector.get方法代码示例

本文整理汇总了TypeScript中angular2/core.ReflectiveInjector.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ReflectiveInjector.get方法的具体用法?TypeScript ReflectiveInjector.get怎么用?TypeScript ReflectiveInjector.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular2/core.ReflectiveInjector的用法示例。


在下文中一共展示了ReflectiveInjector.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(() => {
      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

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

示例5: beforeEach

    beforeEach(() => {
      const rootReducer = combineReducers({
        counter1: counterReducer,
        counter2: counterReducer,
        counter3: counterReducer
      });

      const initialValue = { counter1: 0, counter2: 1 };

      injector = ReflectiveInjector.resolveAndCreate([
        provideStore(rootReducer, initialValue)
      ]);

      store = injector.get(Store);
      dispatcher = injector.get(Dispatcher);
    });
开发者ID:dsebastien,项目名称:store,代码行数:16,代码来源:store_spec.ts

示例6: beforeEach

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

      popup  = injector.get(PopupService);
    });
开发者ID:AdamFaron,项目名称:FOO,代码行数:8,代码来源:popup.service.spec.ts

示例7: beforeEach

    beforeEach(() => {
      //mock providers
      let injector: ReflectiveInjector = ReflectiveInjector.resolveAndCreate([
        HTTP_PROVIDERS,
        UserService,
        HttpService,
        PopupService,
        TokenService,
        provide(NavigationHistoryService, {useClass: MockService}),
        provide(MessageService, {useClass: MockService}),
        provide(XHRBackend, {useClass: MockBackend}),
        provide(LocalStorageService, {useClass: MockLocalStorageService}),
        provide(APP_CONFIG, {useValue: CONFIG})
      ]);

      user = injector.get(UserService);
      xhrBackend = injector.get(XHRBackend);  //mock http backend
    });
开发者ID:AdamFaron,项目名称:FOO,代码行数:18,代码来源:user.service.spec.ts

示例8: describe

  describe('todo integration spec', function() {

    let injector: ReflectiveInjector;
    let store: Store<TodoAppSchema>;
    let currentState: TodoAppSchema;

    const rootReducer = combineReducers({ todos, visibilityFilter });
    const initialValue = { todos: [], visibilityFilter: VisibilityFilters.SHOW_ALL };

    injector = ReflectiveInjector.resolveAndCreate([
      provideStore(rootReducer, initialValue)
    ]);

    store = injector.get(Store);

    store.subscribe(state => {
      currentState = state;
    });

    it('should successfully instantiate', () => {
      expect(store).toBeDefined();
    });

    it('should combine reducers automatically if a key/value map is provided', () => {
      const reducers = { test: function(){} };
      spyOn(reducers, 'test');
      const action = { type: 'Test Action' };
      const reducer = ReflectiveInjector.resolveAndCreate([ provideStore(reducers) ]).get(REDUCER);

      expect(reducer).toBeDefined();
      expect(typeof reducer === 'function').toBe(true);

      reducer(undefined, action);

      expect(reducers.test).toHaveBeenCalledWith(undefined, action);
    });

    it('should probe the reducer to resolve the initial state if no initial state is provided', () => {
      const reducer = () => 2;
      const initialState = ReflectiveInjector.resolveAndCreate([ provideStore(reducer) ]).get(INITIAL_STATE);

      expect(initialState).toBe(2);
    });

    it('should use a provided initial state', () => {
      const reducer = () => 2;
      const initialState = ReflectiveInjector.resolveAndCreate([ provideStore(reducer, 3) ]).get(INITIAL_STATE);

      expect(initialState).toBe(3);
    });

    it('should start with no todos and showing all filter', () => {
      expect(currentState.todos.length).toEqual(0);
      expect(currentState.visibilityFilter).toEqual(VisibilityFilters.SHOW_ALL);
    });

    it('should add a todo', () => {
      store.dispatch({ type: ADD_TODO, payload: { text: 'first todo' } });
      expect(currentState.todos.length).toEqual(1);

      expect(currentState.todos[0].text).toEqual('first todo');
      expect(currentState.todos[0].completed).toEqual(false);
      expect(currentState.todos[0].id).toEqual(1);
    });

    it('should add another todo', () => {
      store.dispatch({ type: ADD_TODO, payload: { text: 'second todo' } });
      expect(currentState.todos.length).toEqual(2);

      expect(currentState.todos[1].text).toEqual('second todo');
      expect(currentState.todos[1].completed).toEqual(false);
      expect(currentState.todos[1].id).toEqual(2);
    });

    it('should complete the first todo', () => {
      store.dispatch({ type: COMPLETE_TODO, payload: { id: 1 } });
      expect(currentState.todos.length).toEqual(2);

      expect(currentState.todos[0].text).toEqual('first todo');
      expect(currentState.todos[0].completed).toEqual(true);
      expect(currentState.todos[0].id).toEqual(1);
    });

    it('should use visibilityFilter to filter todos', () => {

      const filterVisibleTodos = (visibilityFilter, todos) => {
        let predicate;
        if (visibilityFilter === VisibilityFilters.SHOW_ALL) {
          predicate = () => true;
        }
        else if (visibilityFilter === VisibilityFilters.SHOW_ACTIVE) {
          predicate = (todo) => !todo.completed;
        }
        else {
          predicate = (todo) => todo.completed;
        }
        return todos.filter(predicate);
      };

      let currentlyVisibleTodos;
//.........这里部分代码省略.........
开发者ID:dsebastien,项目名称:store,代码行数:101,代码来源:integration_spec.ts

示例9: beforeEach

 beforeEach(() => {
     injector = ReflectiveInjector.resolveAndCreate([STORAGE_PROVIDERS, provide(localStorageBackend, {useClass: MockLocalStorage})]);
     mockStorage = injector.get(localStorageBackend);
 });
开发者ID:ganeshpms,项目名称:spike1,代码行数:4,代码来源:login.spec.ts


注:本文中的angular2/core.ReflectiveInjector.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。