类型'Observable <observable <object [] >>'不可分配给类型'Observable <object []>'

时间:2018-10-22 19:14:19

标签: angular typescript angular7

这曾经在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'.

我尝试使用'any'类型,但仍然有相同的错误。

受影响的代码:

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];
    }

package.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",

1 个答案:

答案 0 :(得分:3)

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

  
    
      

卸下阵列括号[]

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