【发布时间】:2019-11-18 06:38:11
【问题描述】:
我正在使用 OMDB api(在线电影数据库)。我创建了一个返回预期数据类型的接口。通过http get方法请求数据时,返回的数据为:{Search: Array(10), totalResults: "31", Response: "True"}。我需要的数据在搜索数组中。订阅时,我使用 res.Search 访问此信息: subscribe( (res) => { res = this.movieResults = res.Search; 但是错误显示我的界面上不存在搜索。请问我该如何解决?
/* 我的界面 */
export interface SearchInterface {
Poster: string;
Title: string;
Type: string;
Year: string;
imdbID: string;
}
导出默认搜索接口;
/* 我的 Service 中的 get 方法 */
searchFilm(name: string): Observable<SearchInterface> {
return this.http.get<SearchInterface>(this.searchUrl + this.apiKey + '&s=' + name);
}
/* 订阅我的组件中的 observable */
/* GET request*/
getData(event) {
const film = event.target.value;
this.data.searchFilm(film)
.subscribe( (res) => {
/** Sort out res.Search issue */
res = this.movieResults = res.Search;
console.log(res);
});
}
【问题讨论】:
标签: angular rxjs angular2-observables