本文整理汇总了TypeScript中angular2/src/core/di.Injector.resolveAndCreate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Injector.resolveAndCreate方法的具体用法?TypeScript Injector.resolveAndCreate怎么用?TypeScript Injector.resolveAndCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/src/core/di.Injector
的用法示例。
在下文中一共展示了Injector.resolveAndCreate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createInjector
export function createInjector(zone: NgZone, bus: MessageBus): Injector {
BrowserDomAdapter.makeCurrent();
_rootProviders.push(provide(NgZone, {useValue: zone}));
_rootProviders.push(provide(MessageBus, {useValue: bus}));
var injector: Injector = Injector.resolveAndCreate(_rootProviders);
return injector.resolveAndCreateChild(_injectorProviders());
}
示例2: createInjector
export function createInjector(zone: NgZone, bus: MessageBus): Injector {
BrowserDomAdapter.makeCurrent();
_rootBindings.push(bind(NgZone).toValue(zone));
_rootBindings.push(bind(MessageBus).toValue(bus));
var injector: Injector = Injector.resolveAndCreate(_rootBindings);
return injector.resolveAndCreateChild(_injectorBindings());
}
示例3: bind
.then((args) => {
var capabilities = args[0];
var userAgent = args[1];
// This might still create instances twice. We are creating a new injector with all the
// providers.
// Only WebDriverAdapter is reused.
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better.
var injector = Injector.resolveAndCreate([
sampleBindings, bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);
return sampler.sample();
});
示例4: sample
sample({id, execute, prepare, microMetrics, bindings}:
{id: string, execute?: any, prepare?: any, microMetrics?: any, bindings?: any}):
Promise<SampleState> {
var sampleBindings = [
_DEFAULT_PROVIDERS,
this._defaultBindings,
bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute)
];
if (isPresent(prepare)) {
sampleBindings.push(bind(Options.PREPARE).toValue(prepare));
}
if (isPresent(microMetrics)) {
sampleBindings.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
}
if (isPresent(bindings)) {
sampleBindings.push(bindings);
}
var inj = Injector.resolveAndCreate(sampleBindings);
var adapter = inj.get(WebDriverAdapter);
return PromiseWrapper
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
.then((args) => {
var capabilities = args[0];
var userAgent = args[1];
// This might still create instances twice. We are creating a new injector with all the
// providers.
// Only WebDriverAdapter is reused.
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better.
var injector = Injector.resolveAndCreate([
sampleBindings,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);
return sampler.sample();
});
}
示例5: createTestInjector
export function createTestInjector(bindings: Array<Type | Binding | any[]>): Injector {
var rootInjector = Injector.resolveAndCreate(_getRootBindings());
return rootInjector.resolveAndCreateChild(ListWrapper.concat(_getAppBindings(), bindings));
}
示例6: newRequest
import 'reflect-metadata';
import {Injectable, Injector, provide} from 'angular2/src/core/di';
import {SW_PROVIDERS, WorkerScope, WorkerAdapter} from './index';
import {ServiceWorker} from './worker';
import './rxjs';
//importScripts('worker.version.js');
declare var global;
@Injectable()
class BrowserAdapter extends WorkerAdapter {
newRequest(req: string | Request, init?: Object): Request {
return new Request(req, init);
}
newResponse(body: string | Blob): Response {
return new Response(body);
}
}
Injector.resolveAndCreate([
SW_PROVIDERS,
provide(WorkerAdapter, {useClass: BrowserAdapter}),
provide(WorkerScope, {useValue: (typeof self !== 'undefined') ? self : global})
]).get(ServiceWorker);
示例7: bootstrap
}
bootstrap() {
this._logger.log('bootstrap')
}
onInstall(installEvent) {
installEvent.waitUntil(this._onInstall());
}
private _onInstall() {
return Promise.resolve('ready');
}
onActivate(activateEvent) {
this._logger.log('activate', activateEvent);
}
onFetch(fetchEvent) {
this._logger.log('fetch', fetchEvent.request.url);
}
}
Injector
.resolveAndCreate([
SWLogger,
provide(SWContext, { useValue: self }),
NgServiceWorker, ])
.get(NgServiceWorker)
.bootstrap();