本文整理匯總了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);
}
示例2: constructor
constructor(service: Service, injector: Injector) {
this.instance1 = service.instance;
this.instance2 = injector.get(Service).instance;
}
示例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');
});
示例4: function
function(injector: Injector) {
runBlockTriggered = true;
expect(injector.get($INJECTOR)).toBeDefined();
}
示例5: beforeEach
beforeEach(inject([ Injector ], (injector: Injector) => {
audioContext = injector.get<IAudioContext>(AudioContext);
isSupported = injector.get<() => Promise<boolean>>(audioContextModuleIsSupported);
}));
示例6: constructor
constructor(protected injector: Injector) {
this.config = this.injector.get(AppConfig).getConfiguration();
}
示例7:
appRef.registerBootstrapListener(() => { injector.get(Router).initialNavigation(); });
示例8: it
it('merges imports and exports', () => { expect(injector.get(AOT_TOKEN)).toEqual('exports'); });
示例9: beforeEach
beforeEach(() => {
locationService = injector.get(LocationService) as any as MockLocationService;
navService.currentNodes.subscribe(selected => currentNodes = selected);
httpMock.expectOne({}).flush(navJson);
});
示例10: return
return () => {
let zone = injector.get(NgZone);
zone.runGuarded(() => injector.get(MessageBasedPlatformLocation).start());
};