本文整理匯總了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;
}
示例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(() => {
//mock providers
let injector: ReflectiveInjector = ReflectiveInjector.resolveAndCreate([
PopupService
]);
popup = injector.get(PopupService);
});
示例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);
});
示例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);
});
示例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);
}
示例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');
});
});
示例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);
});
示例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();
});
示例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));
}