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


TypeScript core.Injector類代碼示例

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


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

示例1: constructor

 constructor(injector: Injector) {
   this.defaultCounterId = injector.get<string>(DEFAULT_COUNTER_ID);
   this.counterConfigs = injector.get<YandexCounterConfig[]>(YANDEX_COUNTERS_CONFIGS);
   this.positionToId = this.counterConfigs.map(config => config.id);
 }
開發者ID:FriOne,項目名稱:ng-yandex-metrika,代碼行數:5,代碼來源:ng-yandex-metrika.service.ts

示例2: constructor

 constructor(service: Service, injector: Injector) {
   this.instance1 = service.instance;
   this.instance2 = injector.get(Service).instance;
 }
開發者ID:BobChao87,項目名稱:angular,代碼行數:4,代碼來源:lib2.ts

示例3: describe

describe('ResourceService', () => {

  let injector: Injector;
  let resourceService: ResourceService;
  let httpMock: HttpTestingController;

  beforeEach(() => {
    injector = TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [
        ResourceService
      ]
    });

    resourceService = injector.get(ResourceService);
    httpMock = injector.get(HttpTestingController);
  });

  afterEach(() => httpMock.verify());

  it('should make a single connection to the server', () => {
    const req = httpMock.expectOne({});
    expect(req.request.url).toBe('generated/resources.json');
  });

  describe('#categories', () => {

    let categories: Category[];
    let testData: any;

    beforeEach(() => {
      testData = getTestResources();
      httpMock.expectOne({}).flush(testData);
      resourceService.categories.subscribe(results => categories = results);
    });

    it('categories observable should complete', () => {
      let completed = false;
      resourceService.categories.subscribe(null, null, () => completed = true);
      expect(true).toBe(true, 'observable completed');
    });

    it('should reshape contributors.json to sorted category array', () => {
      const actualIds = categories.map(c => c.id).join(',');
      expect(actualIds).toBe('cat-1,cat-3');
    });

    it('should convert ids to canonical form', () => {
      // canonical form is lowercase with dashes for spaces
      const cat = categories[1];
      const sub = cat.subCategories[0];
      const res = sub.resources[0];

      expect(cat.id).toBe('cat-3', 'category id');
      expect(sub.id).toBe('cat3-subcat2', 'subcat id');
      expect(res.id).toBe('cat3-subcat2-res1', 'resources id');
    });

    it('resource knows its category and sub-category titles', () => {
      const cat = categories[1];
      const sub = cat.subCategories[0];
      const res = sub.resources[0];
      expect(res.category).toBe(cat.title, 'category title');
      expect(res.subCategory).toBe(sub.title, 'subcategory title');
    });

    it('should have expected SubCategories of "Cat 3"', () => {
      const actualIds = categories[1].subCategories.map(s => s.id).join(',');
      expect(actualIds).toBe('cat3-subcat2,cat3-subcat1');
    });

    it('should have expected sorted resources of "Cat 1:SubCat1"', () => {
      const actualIds = categories[0].subCategories[0].resources.map(r => r.id).join(',');
      expect(actualIds).toBe('a-a-a,s-s-s,z-z-z');
    });
  });

  it('should do WHAT(?) if the request fails');
});
開發者ID:AnthonyPAlicea,項目名稱:angular,代碼行數:79,代碼來源:resource.service.spec.ts

示例4: function

 function(injector: Injector) {
   runBlockTriggered = true;
   expect(injector.get($INJECTOR)).toBeDefined();
 }
開發者ID:AnthonyPAlicea,項目名稱:angular,代碼行數:4,代碼來源:injection_spec.ts

示例5: beforeEach

 beforeEach(inject([ Injector ], (injector: Injector) => {
     audioContext = injector.get<IAudioContext>(AudioContext);
     isSupported = injector.get<() => Promise<boolean>>(audioContextModuleIsSupported);
 }));
開發者ID:chrisguttandin,項目名稱:angular-audio-context,代碼行數:4,代碼來源:module.ts

示例6: constructor

 constructor(protected injector: Injector) {
   this.config = this.injector.get(AppConfig).getConfiguration();
 }
開發者ID:gatsbimantico,項目名稱:ontimize-web-ngx,代碼行數:3,代碼來源:auth-guard.provider.ts

示例7:

 appRef.registerBootstrapListener(() => { injector.get(Router).initialNavigation(); });
開發者ID:FionaWong,項目名稱:angular,代碼行數:1,代碼來源:router_app_module.ts

示例8: it

 it('merges imports and exports', () => { expect(injector.get(AOT_TOKEN)).toEqual('exports'); });
開發者ID:cyrilletuzi,項目名稱:angular,代碼行數:1,代碼來源:module_spec.ts

示例9: beforeEach

 beforeEach(() => {
   locationService = injector.get(LocationService) as any as MockLocationService;
   navService.currentNodes.subscribe(selected => currentNodes = selected);
   httpMock.expectOne({}).flush(navJson);
 });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:5,代碼來源:navigation.service.spec.ts

示例10: return

  return () => {
    let zone = injector.get(NgZone);

    zone.runGuarded(() => injector.get(MessageBasedPlatformLocation).start());
  };
開發者ID:Brantner,項目名稱:angular,代碼行數:5,代碼來源:location_providers.ts


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