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


TypeScript Injector.get方法代碼示例

本文整理匯總了TypeScript中angular2/core.Injector.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Injector.get方法的具體用法?TypeScript Injector.get怎麽用?TypeScript Injector.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在angular2/core.Injector的用法示例。


在下文中一共展示了Injector.get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: useInjector

export function useInjector() {
  var injector:Injector;

//#enddocregion injector
/*
//#docregion injector-no-new
  // Cannot 'new' an Injector like this!
  var injector = new Injector([Car, Engine, Tires, Logger]);
//#enddocregion injector-no-new
*/

//#docregion injector
  //#docregion injector-create-and-call
  injector = Injector.resolveAndCreate([Car, Engine, Tires, Logger]);
  //#docregion injector-call
  var car = injector.get(Car);
 //#enddocregion injector-call
 //#enddocregion injector-create-and-call
  car.description = 'Injector';

  var logger = injector.get(Logger);
  logger.log('Injector car.drive() said: '+car.drive());

  return car;
}
開發者ID:Bachmann1234,項目名稱:angular.io,代碼行數:25,代碼來源:car-injector.ts

示例2: appInjector

export const authorize = (to: ComponentInstruction, from: ComponentInstruction, params: Object = {}) =>
{
  let injector: Injector = appInjector();
  //let router: Router = injector.get(Router);
  let user$: Observable<User> = injector.get(UserService).user$
  let projects$: Observable<Array<Project>> = injector.get(ProjectsService).projects$

  // checks
  let authorized = false;
  let checkToken = tokenNotExpired(null, localStorage.getItem('token'))
  let checkRole$ = user$.map(user => user.role === 'admin' || user.role === params['checkRole'])
  let checkGroup$ = projects$
    .flatMap(project => project)
    .filter(project => project.url === to.urlPath)
    .zip(user$)
    .map(merged => merged[0].groups.map(projectsGroup => merged[1].groups.indexOf(projectsGroup) !== -1))
    .flatMap(merged => merged)

  Observable
    .merge(checkRole$, checkGroup$)
    .filter(check => check === true)
    .subscribe
    (
      (check: boolean) => authorized = check,
      err => console.error // maybe redirect to custom 4xx page here...
    )

  return new Promise((resolve) => resolve(checkToken && authorized))
}
開發者ID:aberenyi,項目名稱:mean-boilerplate-ts,代碼行數:29,代碼來源:authorize.ts

示例3: beforeEach

	beforeEach(() => {
		injector = Injector.resolveAndCreate([
			BaseRequestOptions,
			MockBackend,
			provide(Http, {
				useFactory: (connectionBackend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
					return new Http(connectionBackend, defaultOptions);
				},
				deps: [
					MockBackend,
					BaseRequestOptions
				]
			}),
			provide(Icon, {
				useFactory: (http: Http) => {
					return new Icon(http);
				},
				deps: [
					Http
				]
			})
		]);
		backend = injector.get(MockBackend);
		store = injector.get(Icon);
		response = new Response(
			new ResponseOptions({body: SVG_GLYPH_HTML})
		);
		glyph = createGlyphNode();
	});
開發者ID:virajs,項目名稱:ng2-lab,代碼行數:29,代碼來源:icon.spec.ts

示例4: appInjector

export const checkAuth = (next: ComponentInstruction, previous: ComponentInstruction) => {
    let injector: Injector = appInjector(); // get the stored reference to the injector
    let auth: Auth = injector.get(Auth);
    let router: Router = injector.get(Router);
    let location: Location = injector.get(Location);

    // return a boolean or a promise that resolves a boolean
    return new Promise((resolve, reject) => {

        if (auth.check()) {
            // already login, redirect to default page
            if (next.urlPath == 'login' || next.urlPath == 'signup') {
                router.navigate(['/Home']);	// r
                // window.location.href = 'index.html';
                resolve(false);
            }
            // show the page
            else {
                resolve(true);
            }
        } else {
            // not login; show the login page
            if (next.urlPath == 'login' || next.urlPath == 'signup') {
                resolve(true);
            }
            // restrict the page
            else {
                router.navigate(['/Login']); // r
                // window.location.href = 'login.html';
                resolve(false);
            }
        }
    });
};
開發者ID:ClaudePlos,項目名稱:profus_dashboard,代碼行數:34,代碼來源:check_auth.ts

示例5: beforeEach

    beforeEach(() => {

      injector = Injector.resolveAndCreate([
        provideStore({ counter1: counterReducer, counter2: counterReducer, counter3: counterReducer }, { counter1: 0, counter2: 1 })
      ]);

      store = injector.get(Store);
      dispatcher = injector.get(Dispatcher);
    });
開發者ID:Konviser,項目名稱:todo-list,代碼行數:9,代碼來源:store_spec.ts

示例6: beforeEach

 beforeEach(() => {
     injector = Injector.resolveAndCreate([
         HTTP_PROVIDERS,
         GithubComponent,
         GithubService,
         Config
     ]);
     component = injector.get(GithubComponent);
     service = injector.get(GithubService);
     sinon.spy(service, "searchRepositories");
 });
開發者ID:tomastrajan,項目名稱:complete-angular2-seed,代碼行數:11,代碼來源:github-component-integration-test.ts

示例7: beforeEach

 beforeEach(() => {
     injector = ReflectiveInjector.resolveAndCreate([
         HTTP_PROVIDERS,
         // Provide a mocked (fake) backend for Http
         provide(XHRBackend, {useClass: MockBackend}),
         TRANSLATE_PROVIDERS
     ]);
     backend = injector.get(XHRBackend);
     translate = injector.get(TranslateService);
     // sets the connection when someone tries to access the backend with an xhr request
     backend.connections.subscribe((c: MockConnection) => connection = c);
 });
開發者ID:DanielKucal,項目名稱:ng2-translate,代碼行數:12,代碼來源:translate.service.spec.ts

示例8: CanActivate

    return CanActivate((to: ComponentInstruction, from: ComponentInstruction, target = ['/']) => {
        let injector: Injector = appInjector(); // Get the stored reference to the application injector
        let tokenService: TokenService = injector.get(TokenService);
        let router: Router = injector.get(Router);

        if (tokenService.token)
            return true;

        router.navigate(['/Login', { target }]);
        
        return false;
    });
開發者ID:dmorosinotto,項目名稱:angularjs-days-2016-munich,代碼行數:12,代碼來源:needsAuthentication.ts

示例9: provide

 var prepare = (loaderClass: Function) => {
     injector = Injector.resolveAndCreate([
         HTTP_PROVIDERS,
         // Provide a mocked (fake) backend for Http
         provide(XHRBackend, {useClass: MockBackend}),
         provide(TranslateLoader, {useClass: loaderClass}),
         TranslateService
     ]);
     backend = injector.get(XHRBackend);
     translate = injector.get(TranslateService);
     // sets the connection when someone tries to access the backend with an xhr request
     backend.connections.subscribe((c: MockConnection) => connection = c);
 };
開發者ID:teyosh,項目名稱:ng2-translate,代碼行數:13,代碼來源:translate.service.spec.ts

示例10: provide

 let prepare = ((handlerClass: Function) => {
     injector = ReflectiveInjector.resolveAndCreate([
         HTTP_PROVIDERS,
         // Provide a mocked (fake) backend for Http
         provide(XHRBackend, {useClass: MockBackend}),
         TRANSLATE_PROVIDERS,
         provide(MissingTranslationHandler, {useClass: handlerClass})
     ]);
     backend = injector.get(XHRBackend);
     translate = injector.get(TranslateService);
     missingTranslationHandler = injector.get(MissingTranslationHandler);
     // sets the connection when someone tries to access the backend with an xhr request
     backend.connections.subscribe((c: MockConnection) => connection = c);
 });
開發者ID:DanielKucal,項目名稱:ng2-translate,代碼行數:14,代碼來源:translate.service.spec.ts


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