当前位置: 首页>>代码示例>>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;未经允许,请勿转载。