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


TypeScript di.Key類代碼示例

本文整理匯總了TypeScript中angular2/di.Key的典型用法代碼示例。如果您正苦於以下問題:TypeScript Key類的具體用法?TypeScript Key怎麽用?TypeScript Key使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Key類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

 constructor() {
   this.viewId = Key.get(viewModule.View).id;
   this.ngElementId = Key.get(NgElement).id;
   this.viewContainerId = Key.get(ViewContainer).id;
   this.bindingPropagationConfigId = Key.get(BindingPropagationConfig).id;
   this.privateComponentLocationId = Key.get(pclModule.PrivateComponentLocation).id;
 }
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:7,代碼來源:element_injector.ts

示例2: directiveBinding

function directiveBinding({metadata}: {metadata?: any} = {}) {
  return new DirectiveBinding(Key.get("dummy"), null, [], [], [], metadata);
}
開發者ID:lavinjj,項目名稱:angular,代碼行數:3,代碼來源:proto_view_factory_spec.ts

示例3: main

export function main() {
  BrowserDomAdapter.makeCurrent();
  var iterations = getIntParameter('iterations');

  // This benchmark does not use bootstrap and needs to create a reflector
  setupReflector();
  var bindings = [A, B, C, D, E];
  var injector = Injector.resolveAndCreate(bindings);

  var D_KEY = Key.get(D);
  var E_KEY = Key.get(E);
  var childInjector = injector.resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([]);

  var variousBindings = [A, bind(B).toClass(C), [D, [E]], bind(F).toValue(6)];

  var variousBindingsResolved = Injector.resolve(variousBindings);

  function getByToken() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D);
      injector.get(E);
    }
  }
  function getByKey() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D_KEY);
      injector.get(E_KEY);
    }
  }

  function getChild() {
    for (var i = 0; i < iterations; ++i) {
      childInjector.get(D);
      childInjector.get(E);
    }
  }

  function instantiate() {
    for (var i = 0; i < iterations; ++i) {
      var child = injector.resolveAndCreateChild([E]);
      child.get(E);
    }
  }

  /**
   * Creates an injector with a variety of binding types.
   */
  function createVariety() {
    for (var i = 0; i < iterations; ++i) {
      Injector.resolveAndCreate(variousBindings);
    }
  }

  /**
   * Same as [createVariety] but resolves bindings ahead of time.
   */
  function createVarietyResolved() {
    for (var i = 0; i < iterations; ++i) {
      Injector.fromResolvedBindings(variousBindingsResolved);
    }
  }

  bindAction('#getByToken', () => microBenchmark('injectAvg', iterations, getByToken));
  bindAction('#getByKey', () => microBenchmark('injectAvg', iterations, getByKey));
  bindAction('#getChild', () => microBenchmark('injectAvg', iterations, getChild));
  bindAction('#instantiate', () => microBenchmark('injectAvg', iterations, instantiate));
  bindAction('#createVariety', () => microBenchmark('injectAvg', iterations, createVariety));
  bindAction('#createVarietyResolved',
             () => microBenchmark('injectAvg', iterations, createVarietyResolved));
}
開發者ID:goderbauer,項目名稱:angular,代碼行數:74,代碼來源:di_benchmark.ts

示例4: expect

 expect(() => Key.setMetadata(key, "meta2")).toThrowError();
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:1,代碼來源:key_spec.ts

示例5: it

 it("should throw when assigning different metadata", function() {
   var key = registry.get('car');
   Key.setMetadata(key, "meta1");
   expect(() => Key.setMetadata(key, "meta2")).toThrowError();
 });
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:5,代碼來源:key_spec.ts

示例6: hasPreBuiltObject

 hasPreBuiltObject(type) {
   var pb = this._getPreBuiltObjectByKeyId(Key.get(type).id);
   return pb !== _undefined && isPresent(pb);
 }
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:4,代碼來源:element_injector.ts

示例7: hasDirective

 hasDirective(type) {
   return this._getDirectiveByKeyId(Key.get(type).id) !== _undefined;
 }
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:3,代碼來源:element_injector.ts

示例8: get

 get(token) {
   return this._getByKey(Key.get(token), 0, false, null);
 }
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:3,代碼來源:element_injector.ts


注:本文中的angular2/di.Key類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。