當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript di.Injector類代碼示例

本文整理匯總了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;未經允許,請勿轉載。