本文整理汇总了TypeScript中@angular/core.Injector.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Injector.get方法的具体用法?TypeScript Injector.get怎么用?TypeScript Injector.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/core.Injector
的用法示例。
在下文中一共展示了Injector.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: genModule
function genModule(options: DelonAuthConfig, tokenData?: JWTTokenModel) {
injector = TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
RouterTestingModule.withRoutes([]),
DelonAuthModule.forRoot(),
],
providers: [
{ provide: DelonAuthConfig, useValue: options },
{ provide: Router, useValue: mockRouter },
{ provide: HTTP_INTERCEPTORS, useClass: JWTInterceptor, multi: true },
],
});
if (tokenData) injector.get(DA_SERVICE_TOKEN).set(tokenData);
http = injector.get(HttpClient);
httpBed = injector.get(HttpTestingController);
}
示例2:
return actionSchemas.map(schema => {
let action: BaseAction<T> = this.injector.get(schema.action); // Prototype Scope
action.label = schema.label;
action.icon = schema.icon;
Object.assign(action, schema.data);
Object.assign(action, context);
return action;
});
示例3: constructor
constructor(injector: Injector) {
try {
this.ionicErrorHandler = injector.get(IonicErrorHandler);
} catch(e) {
// Unable to get the IonicErrorHandler provider, ensure
// IonicErrorHandler has been added to the providers list below
}
}
示例4: _document
function _document(injector: Injector) {
let config: PlatformConfig|null = injector.get(INITIAL_CONFIG, null);
if (config && config.document) {
return parseDocument(config.document);
} else {
return getDOM().createHtmlDocument();
}
}
示例5: return
return () => {
BrowserDomAdapter.makeCurrent();
wtfInit();
BrowserGetTestability.init();
var scriptUri: string;
try {
scriptUri = injector.get(WORKER_SCRIPT);
} catch (e) {
throw new BaseException(
'You must provide your WebWorker\'s initialization script with the WORKER_SCRIPT token');
}
let instance = injector.get(WebWorkerInstance);
spawnWebWorker(scriptUri, instance);
initializeGenericWorkerRenderer(injector);
};
示例6: function
originalWhenStable.call(this, function() {
const ng2Testability: Testability = injector.get(Testability);
if (ng2Testability.isStable()) {
callback.apply(this, arguments);
} else {
ng2Testability.whenStable(newWhenStable.bind(this, callback));
}
});
示例7: intercept
intercept(req, next) {
const authService = this.injector.get(AuthService);
const tokenizedReq = req.clone({
setHeaders: {
Authorization: 'Bearer ' + authService.getToken()
}
});
return next.handle(tokenizedReq);
}
示例8: appInjector
export const hasPermission = (next: ComponentInstruction, previous: ComponentInstruction, permissionName: string) => {
let injector: Injector = appInjector(); // get the stored reference to the injector
let authService: AuthenticationService = injector.get(AuthenticationService);
let router: Router = injector.get(Router);
// return a boolean or a promise that resolves a boolean
return new Promise((resolve) => {
authService.hasPermission(permissionName)
.subscribe((result) => {
if (result) {
resolve(true);
} else {
router.navigate(['/PermissionDenied']);
resolve(false);
}
});
});
};
示例9: function
originalWhenStable.call(testabilityDelegate, function() {
const ng2Testability: Testability = injector.get(Testability);
if (ng2Testability.isStable()) {
callback();
} else {
ng2Testability.whenStable(
newWhenStable.bind(testabilityDelegate, callback));
}
});
示例10: getRootViewContainerRef
/**
* This is a name conventional class to get application root view component ref
* to made this method working you need to add:
* ```typescript
* @Component({
* selector: 'my-app',
* ...
* })
* export class MyApp {
* constructor(viewContainerRef: ViewContainerRef) {
* // A Default view container ref, usually the app root container ref.
* // Has to be set manually until we can find a way to get it automatically.
* this.viewContainerRef = viewContainerRef;
* }
* }
* ```
* @returns {ViewContainerRef} - application root view component ref
*/
public getRootViewContainerRef():ViewContainerRef {
// The only way for now (by @mhevery)
// https://github.com/angular/angular/issues/6446#issuecomment-173459525
// this is a class of application bootstrap component (like my-app)
const classOfRootComponent = this.applicationRef.componentTypes[0];
// this is an instance of application bootstrap component
const appInstance = this.injector.get(classOfRootComponent);
return appInstance.viewContainerRef;
}