• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.Injector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中angular2/core.Injector的典型用法代码示例。如果您正苦于以下问题:TypeScript Injector类的具体用法?TypeScript Injector怎么用?TypeScript Injector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Injector类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: 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


示例2: beforeEach

 beforeEach(() => {
   injector = Injector.resolveAndCreate([
     TestService,
     provideStore({test}, {}),
   ]);
   testService = injector.get(TestService);
 });
开发者ID:nathasm,项目名称:angular2-webpack-starter,代码行数:7,代码来源:TestService.spec.ts


示例3: 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


示例4: 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


示例5: 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


示例6: beforeEach

  beforeEach(() => {
    injector = Injector.resolveAndCreate([
      DB.DB_PROVIDERS,
      DB.provideDB(todoAppSchema)
    ]);

    idb = injector.get(DB.Database);
  });
开发者ID:MikeRyan52,项目名称:db,代码行数:8,代码来源:db_spec.ts


示例7: constructor

 constructor( private name: string) {
   console.log('component');
   console.log(this.name);
   
   let injector:Injector = appInjector();
   this.svc = injector.get(NavService);
   console.log(this.svc);
 }
开发者ID:deostroll,项目名称:sboard,代码行数:8,代码来源:navigation.ts


示例8: beforeEach

    beforeEach(() => {

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

      store = injector.get(Store);
    });
开发者ID:drew-moore,项目名称:store,代码行数:8,代码来源:store_spec.ts


示例9: isAuthorized

	static isAuthorized() {
		let injector: Injector = appInjector()
		let router: Router = injector.get(Router)

		return new Promise((resolve) => {
			if(!UserService.isAuthenticated()) {
				router.navigate(['Login'])
			}
			resolve(UserService.isAuthenticated())
		})
	}
开发者ID:PeteOyable,项目名称:lili,代码行数:11,代码来源:authentication.service.ts


示例10: 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



注:本文中的angular2/core.Injector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.IterableDiffers类代码示例发布时间:2022-05-25
下一篇:
TypeScript core.EventEmitter类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap