Executing resolvers one after the other in Angular 2+

后端 未结 4 1688
孤城傲影
孤城傲影 2021-02-04 03:50

Given the following route:

path: \'\',
component: MyComponent,
resolve: {
    foo: FooResolver,
    bar: BarResolver
}

Is there any way of tell

4条回答
  •  心在旅途
    2021-02-04 04:41

    I found a slightly more elegant solution that can be used if you don't care about the results from all of the resolvers:

    class FooBarResolver implements Resolve> {
        constructor(
            protected fooResolver: FooResolver,
            protected barResolver: BarResolver
        ) { }
    
        resolve(): Observable
        {
            return this.fooResolver.resolve().pipe(
                concat(this.barResolver.resolve()),
                concat(this.barResolver.resolve())
            );
        }
    }
    

    I use this to trigger the data loading in my services. And because they write the data / isLoading / error into an Akita storage, I don't care about the results of the resolvers.

提交回复
热议问题