【发布时间】:2019-07-14 13:08:58
【问题描述】:
是的,所以我正在遍历一组信息,并且信息显示了我想要的方式,但是,我的控制台中出现了一些看起来很奇怪的错误:ERROR TypeError: "_v.context.$implicit is undefined"
api服务:
private extractData(res: Response) {
let body = res;
return body || {};
}
getWeather(city: string, isoCode: string): Observable<any> {
return this.http.get(`${this.endPoint}${city},${isoCode}${this.constants.apiKey}`)
.pipe(map(this.extractData));
}
使用 api 服务的组件:
theWeather:any = [];
countryList = COUNTRIES;
isLoading: boolean = true;
showWeather: boolean = false;
constructor(private apiCall:ApiService) { }
ngOnInit() {
this.retrieveWeather()
};
retrieveWeather() {
console.log('COUNTRY LIST', this.countryList);
this.theWeather = [];
this.countryList.map((element, i) => {
this.apiCall.getWeather(element.city, element.countryIso)
.subscribe((data: {}) => {
element.weatherInfo = data;
});
this.isLoading = false;
});
this.showWeather = true;
};
和html文件:
<div class="country-container">
<div *ngIf="isLoading">
<mat-card>
<mat-progress-spinner class="spinner-style" color="primary" mode="indeterminate"></mat-progress-spinner>
</mat-card>
</div>
<div *ngIf="showWeather" class="card-container">
<mat-card *ngFor="let c of countryList" class="card">
<mat-card-title>Weather for: {{c.city}}, {{c.countryName}}</mat-card-title>
<mat-card-content>The current weather is: {{c.weatherInfo.weather[0].description}}</mat-card-content>
</mat-card>
</div>
</div>
感谢您的帮助!
编辑:使标题更具体地针对问题。
【问题讨论】:
-
Countries 组件中的第 9 行是哪一行?国家/地区是什么样的?
-
@DeborahK 这是 html 组件中的第 9 行:
Weather for: {{c.city}}, {{c.countryName}}标题> -
对不起,错误在 html 中,而不是在组件中。根据错误消息,html 的第 9 行是什么?
-
@DeborahK 抱歉,我看到之后更新了回复。
-
以下是我在谷歌上搜索错误消息时提出的一些建议:stackoverflow.com/questions/47008316/…, stackoverflow.com/questions/44944637/…
标签: javascript angular angular-components