我收到错误 404,它没有找到 http://localhost:4200/assets/icons/weather/.svg
在我的 html 中
list.component.html
<img src="./assets/icons/weather/{{ weatherClass?.img }}.svg" width="130px" />
天气.服务
export class Weather {
constructor(
public locName: string,
public temp: string,
public img: string,
public type:string,
public tempMin:string,
public tempMax:string,
public countryName: string,
public sunrise: string,
public sunset: string) {}
}
list.componen.ts
this.weatherService.currentLocation(this.lat, this.lon).subscribe(data => {
let sunset = format(new Date(data.sys.sunset * 1000), 'hh:mm a');
this.weatherClass = new Weather(
data.name,
data.main.temp,
data.weather[0].icon,
data.weather[0].description,
data.main.temp_max,
data.main.temp_min,
data.sys.country
);
return this.weatherClass;
});
最佳答案
您无法从 observable 返回 this.weatherClass
。相反,您可以在初始化后显示图像。
<img *ngIf="weatherClass" src="{{ './assets/icons/weather/' + weatherClass.img + '.svg' }}" width="130px" />
关于javascript - 如何以 Angular 修复 404(未找到),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58372338/