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


TypeScript Injector.get方法代碼示例

本文整理匯總了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);
 }
開發者ID:wexz,項目名稱:delon,代碼行數:17,代碼來源:jwt.interceptor.spec.ts

示例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;
 });
開發者ID:agmoura,項目名稱:lab-angular2,代碼行數:8,代碼來源:actions.ts

示例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
   }
 }
開發者ID:wmswina,項目名稱:todo,代碼行數:8,代碼來源:app.module.ts

示例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();
  }
}
開發者ID:cooperka,項目名稱:angular,代碼行數:8,代碼來源:server.ts

示例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);
  };
開發者ID:ScottSWu,項目名稱:angular,代碼行數:17,代碼來源:worker_render.ts

示例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));
   }
 });
開發者ID:DzmitryShylovich,項目名稱:angular,代碼行數:8,代碼來源:upgrade_module.ts

示例7: intercept

 intercept(req, next) {
   const authService = this.injector.get(AuthService);
   const tokenizedReq = req.clone({
     setHeaders: {
       Authorization: 'Bearer ' + authService.getToken()
     }
   });
   return next.handle(tokenizedReq);
 }
開發者ID:Khasanboy,項目名稱:Shop-Angular-SpringBoot,代碼行數:9,代碼來源:token-interceptor.service.ts

示例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);
				}
			});
	});
};
開發者ID:shawnrmoss,項目名稱:sms,代碼行數:18,代碼來源:has-permission.ts

示例9: function

 originalWhenStable.call(testabilityDelegate, function() {
   const ng2Testability: Testability = injector.get(Testability);
   if (ng2Testability.isStable()) {
     callback();
   } else {
     ng2Testability.whenStable(
         newWhenStable.bind(testabilityDelegate, callback));
   }
 });
開發者ID:marclaval,項目名稱:angular,代碼行數:9,代碼來源:upgrade_module.ts

示例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;
 }
開發者ID:CardosoGit,項目名稱:ng2-bootstrap,代碼行數:27,代碼來源:components-helper.service.ts


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