本文整理匯總了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;
}
示例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');
});
示例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);
});
示例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);
});
示例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);
});
示例6: beforeEach
beforeEach(() => {
//mock providers
let injector: ReflectiveInjector = ReflectiveInjector.resolveAndCreate([
PopupService
]);
popup = injector.get(PopupService);
});
示例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
});
示例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;
//.........這裏部分代碼省略.........
示例9: beforeEach
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([STORAGE_PROVIDERS, provide(localStorageBackend, {useClass: MockLocalStorage})]);
mockStorage = injector.get(localStorageBackend);
});