类型'Object'不提供签名'(artistongs:string):string'的匹配项。ts(2322)

问题描述 投票:0回答:1
artistSelected(item: any) {
    console.log(item.artist);
    this.songsServices.getSongsListArtist(item.artist).subscribe(
      result => {
        this.songsServices.artistList = result;
        this.route.navigate(['./artistsongs']);
      },
      error => {
        console.log('There is an error');
      }
    );
  }

Service 

getSongsListArtist(album: string) {
        const completeUrl = `${environment.API_URL}?album=${album}`;
        return this.httpClient.get(encodeURI(completeUrl));
    }
    artistList(artistsongs: string) {
        return artistsongs;
    }

我在这方面面临错误。请怪我如何通过使用服务将对象从一个ts文件传递到另一个ts文件。

ionic-framework
1个回答
0
投票
artistList(artistsongs: string) {
        return artistsongs;
    }

更改为

artistList(artistsongs: any) {
        return artistsongs;
    }

据我了解,当您调用getSongsListArtist时,它将返回一个数组对象或一个不仅是字符串的对象。您可以使用typeof()检查this.httpClient.get(encodeURI(completeUrl))返回哪种类型。

© www.soinside.com 2019 - 2024. All rights reserved.