我收到一个错误404,找不到http://localhost:4200/assets/icons/weather/.svg
在我的html中
list.component.html
const signin = user => {
console.log('user', user);
return fetch('http://localhost:9000/auth/signin/', {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
Accept: 'application/json',
},
credentials: 'include',
body: JSON.stringify(user),
})
.then(response => {
return response.json();
})
.catch(err => console.log(err));
};
天气服务
<img src="./assets/icons/weather/{{ weatherClass?.img }}.svg" width="130px" />
list.componen.ts
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) {}
}
答案 0 :(得分:5)
您无法从观察对象返回this.weatherClass
。代替它,您可以在图像初始化后显示它。
<img *ngIf="weatherClass" src="{{ './assets/icons/weather/' + weatherClass.img + '.svg' }}" width="130px" />