本文整理匯總了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;
}