ABC*_*ABC 0 javascript angular
我收到错误404,但找不到http:// localhost:4200 / assets / icons / weather / .svg
在我的HTML中
list.component.html
<img src="./assets/icons/weather/{{ weatherClass?.img }}.svg" width="130px" />
Run Code Online (Sandbox Code Playgroud)
天气服务
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) {}
}
Run Code Online (Sandbox Code Playgroud)
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;
});
Run Code Online (Sandbox Code Playgroud)
您无法this.weatherClass从可观察到的位置返回。代替它,您可以在图像初始化后显示它。
<img *ngIf="weatherClass" src="{{ './assets/icons/weather/' + weatherClass.img + '.svg' }}" width="130px" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45 次 |
| 最近记录: |