角度微调隐藏功能不起作用

问题描述

在我的应用程序中,我有一个微调器,它在 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");
    }

解决方法

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())
    );
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...