且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Http请求上的加载指示器

更新时间:2023-12-05 17:16:34

使用内置的defer运算符设法查找解决方案,该运算符等待订阅并返回新鲜的Observable:

Managed to find a solution using the built in defer operator which waits for a subscription and returns a fresh observable:

getMyHttpObservable(...) {
    const myHttpObservable = createRequestObservable(...);
    return Observable.defer(() => {
        setLoadingIndicator(true);
        return myHttpObservable.finally(() => setLoadingIndicator(false));
    });
}

又矮又短.