RxJS Pipe does not work in Angular Resolver (but works fine in ngOnInit)

时间:2017-12-18 08:38:39

标签: angular routing rxjs resolver

we tried to add a RxJS pipe in our Angular Resolver: the resolver process starts but doesn't end, so we can't show the result in our html component.

Otherwhise, everything works correctly if we move the pipe on the ngOnInit method of the main component.

What are we doing wrong?

Example with myResolver.ts (Resolve doesn’t end his process):

 <add key="serviceLink" value="http://someservice.com/Service.asmx"/>
 <add key="serviceClientClassName" value="serviceClientSoapClient"/>
 <add key="serviceMethod" value="getValues"/>

Example with ngOnInit on mainComponent.ts (it works!):

resolve(): Observable<any> | Promise<any> | any {

    let T = mergeMap((user: firebase.User) => {return Observable.fromPromise(user.getIdToken()) });

    let D = mergeMap((token: string) => { return this.http.get('https://myfakedomain.com/user?access_token=' + token) });

    let P = this.afAuth.authState // return Observable<User>

    .pipe(

    T, D

    )

    return P;

    }

1 个答案:

答案 0 :(得分:1)

找到答案here,它应该适用。

似乎必须在转换运算符旁边添加一个过滤运算符(例如first,last,take ...),以正确返回结果。

问题所在的行:let P = this.afAuth.authState.pipe(T, D)
应该使用过滤运算符进行扩展,例如:let P = this.afAuth.authState.pipe(T, D, first())

相关问题