加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在Angular 2中一个接一个地执行解析器

发布时间:2020-12-17 07:52:26 所属栏目:安全 来源:网络整理
导读:鉴于以下路线: path: '',component: MyComponent,resolve: { foo: FooResolver,bar: BarResolver} 有没有办法告诉angular执行第一个解析器FooResolver,只有在第一个解析器完成后才执行第二个解析器BarResolver? 解析器并行解析.如果Foo和Bar应该被串联解析
鉴于以下路线:
path: '',component: MyComponent,resolve: {
    foo: FooResolver,bar: BarResolver
}

有没有办法告诉angular执行第一个解析器FooResolver,只有在第一个解析器完成后才执行第二个解析器BarResolver?

解析器并行解析.如果Foo和Bar应该被串联解析,它们应该是一个FooBar解析器.如果它们应该在其他路径中自己使用,FooBar可以包装Foo和Bar解析器:
class FooBarResolver implements Resolve<{ foo: any,bar: any }> {
  constructor(
    protected fooResolver: FooResolver,protected barResolver: BarResolver
  ) {}

  async resolve(route): Promise<{ foo: any,bar: any }> {
    const foo = await this.fooResolver.resolve(route);
    const bar = await this.barResolver.resolve(route);

    return { foo,bar };
  }
}

FooBar应该知道这个事实,如果它是从Foo和Bar返回的promise或者observable,以便正确地解决它们.否则应添加额外的安全设备,例如await Observable.from(this.fooResolver.resolve(route)).toPromise().

FooBar和Foo或Bar不应出现在同一路径中,因为这会导致重复的分辨率.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读