0

这曾经在 Angular 2/4 中工作,但自从我升级到 Angular 7 后,我在整个应用程序中都收到了这个错误。突然可能是什么问题?

Type 'Observable<Observable<Object[]>>' is not assignable to type 'Observable<Object[]>'


Type 'Observable<Object>' is not assignable to type 'Observable<object[]>'.
  Type 'Object' is not assignable to type 'object[]'.
    The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
      Property 'includes' is missing in type 'Object'.

我尝试使用“任何”类型,但它仍然有同样的错误。

受影响的代码:

getProfiles(): Observable<any[]> {
    const _url: string = this._serviceUrl + 'api/GetUserProfiles/';
    return this._http.get(_url)
        .catch(this.handleError);
}

调用者方法

 this._exceptionService.getProfiles().subscribe(data => {
    this.data = data[0];
    }

包.json

"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/material": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/router": "^7.0.0",
4

1 回答 1

4

我之前遇到过这个问题。更改您的 Observable 以返回任何

删除数组括号 []

  getProfiles(): Observable<any> {
        const _url: string = this._serviceUrl + 'api/GetUserProfiles/';
        return this._http.get(_url)
            .catch(this.handleError);
    }
于 2018-10-22T20:39:34.017 回答