本文整理汇总了TypeScript中angular2/di.Injector类的典型用法代码示例。如果您正苦于以下问题:TypeScript Injector类的具体用法?TypeScript Injector怎么用?TypeScript Injector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Injector类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should bind to an alias', function() {
var injector = new Injector([Engine, bind(SportsCar).toClass(SportsCar), bind(Car).toAlias(SportsCar)]);
var car = injector.get(Car);
var sportsCar = injector.get(SportsCar);
expect(car).toBeAnInstanceOf(SportsCar);
expect(car).toBe(sportsCar);
});
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:7,代码来源:injector_spec.ts
示例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());
}
开发者ID:KenWilliamson,项目名称:Angular2HostedMobileApp,代码行数:7,代码来源:di_bindings.ts
示例3: _createAppInjector
function _createAppInjector(appComponentType, bindings, zone) {
if (isBlank(_rootInjector))
_rootInjector = new Injector(_rootBindings);
var mergedBindings = isPresent(bindings) ? ListWrapper.concat(_injectorBindings(appComponentType), bindings) : _injectorBindings(appComponentType);
ListWrapper.push(mergedBindings, bind(VmTurnZone).toValue(zone));
return _rootInjector.createChild(mergedBindings);
}
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:7,代码来源:application.ts
示例4: it
it('should return a promise when instantiating a sync binding ' + 'with an async dependency', inject([AsyncTestCompleter], (async) => {
var injector = new Injector([bind(UserList).toAsyncFactory(fetchUsers), UserController]);
injector.asyncGet(UserController).then(function(userController) {
expect(userController).toBeAnInstanceOf(UserController);
expect(userController.list).toBeAnInstanceOf(UserList);
async.done();
});
}));
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:8,代码来源:async_spec.ts
示例5: BaseException
/**
* Creates an `AppView` for the given component.
*
* Only either a component or a context needs to be specified but both can be provided for
* advanced use cases (ie subclassing the context).
*
* @param {Type} component
* @param {*} context
* @param {string} html Use as the component template when specified (shortcut for
* setInlineTemplate)
* @return {Promise<ViewProxy>}
*/
createView(component: Type,
{context = null,
html = null}: {context?: any, html?: string} = {}): Promise<ViewProxy> {
if (isBlank(component) && isBlank(context)) {
throw new BaseException('You must specified at least a component or a context');
}
if (isBlank(component)) {
component = getTypeOf(context);
} else if (isBlank(context)) {
context = instantiateType(component);
}
if (isPresent(html)) {
this.setInlineTemplate(component, html);
}
var doc = this._injector.get(DOCUMENT_TOKEN);
var rootEl = el('<div id="root"></div>');
DOM.appendChild(doc.body, rootEl);
var componentBinding = bind(component).toValue(context);
return this._injector.get(DynamicComponentLoader)
.loadAsRoot(componentBinding, '#root', this._injector)
.then((hostComponentRef) => { return new ViewProxy(hostComponentRef); });
}
开发者ID:Bogatinov,项目名称:angular,代码行数:38,代码来源:test_bed.ts
注:本文中的angular2/di.Injector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论