【问题标题】:Angular Spinner Hide Function Doesn't Work角微调器隐藏功能不起作用
【发布时间】:2021-10-02 04:22:54
【问题描述】:

在我的应用程序中,我有一个微调器,它在 GET 函数完成后停止。对于一个屏幕,即使GET 函数在网络中看起来已经完成,微调器也不会隐藏。计数器永远不会变为 0。可能是什么问题?

微调服务:

private _spinner: FuseSpinnerComponent;
    private _callCount: number = 0;
    public hide(): void {
    
            this._callCount--;
            if (this._spinner && this._callCount <= 0) {
                this._spinner.Hide();
            }
        }

HTTP 服务:

get(url: string, contentType?: ContentTypes): Observable<any> {

    this._spinner.show();

    return this._http.get(this.baseUri + url, { headers: this.getHeader(contentType) }).pipe(
        catchError((err: any) => this.handleError(err)),
        finalize(() => {
            this._spinner.hide();
        }),);
}

屏幕:

if (state.url.indexOf("/admin/contact-list") >= 0) {
            return new Promise((resolve, reject) => {
                Promise.all([
                    this.getContactList(),
                    this.getGeoTypeList(),
                    this.getSectorTypeList(),
                ]).then(
                    ([results]) => {
                        resolve([]);
                    },
                    reject
                );
            });
        }

    getContactList() {
        return new Promise((resolve, reject) => {
            this._http
                .get("Crm/GetContactList/")
                .subscribe((response: IContact[]) => {
                    this.contactList = response;
                    this.onContactListChanged.next(
                        this.contactList
                    );
                    resolve(this.contactList);
                }, reject);
        });
    }
        getGeoTypeList(): Observable<IGeoType[]> {
        return this._http.get("Parameter/GetGeoTypeList");
    }

    getSectorTypeList(): Observable<IGeoType[]> {
        return this._http.get("Parameter/GetSectorTypeList");
    }

【问题讨论】:

    标签: angular typescript fuse


    【解决方案1】:

    Http 客户端请求是冷的,您必须订阅它们才能获取数据。

    get(url: string, contentType?: ContentTypes): Observable<any> {
    
    this._spinner.show();
    
    return this._http.get(this.baseUri + url, { headers: 
      this.getHeader(contentType) }).pipe(
        catchError((err: any) => this.handleError(err)),
       }).subscribe( _ => this._spinner.hide())
        );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 2017-09-13
      相关资源
      最近更新 更多