Angular RxJS:未执行Http请求

时间:2019-06-03 11:40:53

标签: angular typescript

我有两个可观察的东西:

let editClick$ = Observable.fromEvent(this.editButton.nativeElement, 'click');

因此,对于每个click事件:

private editing$: Observable<boolean>;

this.editing$ = editClick$
    .pipe(switchMap(() => this.service.push()));

我的service.push是:

public push(): Observable<boolean> {
    const buildURL = () => map(() => this.buildPushURL());
    const makeRequest = () => switchMap((url: string) => this.httpService.put(url));
    const buildResponse = () => map(() => true);
    const onErrorEmptyUser = () => catchError<boolean, never>(() => Observable.of(false));

    return Observable.of()
        .pipe(
            buildURL(),
            makeRequest(),
            buildResponse(),
            onErrorEmptyUser()
        );
}

当我单击按钮并发出任何请求时,就会出现问题。

我使用async方法创建sybscription:

<button #editButton [disabled]="editing$ | async" class="btn btn-primary">

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Http请求仅在调用subscribe时执行。直到此呼叫请求停止。

希望这会有所帮助。