我有两个可观察的东西:
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">
有什么想法吗?
答案 0 :(得分:0)
Http请求仅在调用subscribe时执行。直到此呼叫请求停止。
希望这会有所帮助。