【问题标题】:How fixed the 404 (Not Found) in angular如何以角度固定 404(未找到)
【发布时间】:2019-10-14 07:55:50
【问题描述】:

我收到一个错误 404,它没有找到 http://localhost:4200/assets/icons/weather/.svg

在我的 html 中

list.component.html

 <img src="./assets/icons/weather/{{ weatherClass?.img }}.svg" width="130px" />

weather.services

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;
      });

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    你不能从 observable 返回this.weatherClass。代替它,您可以在初始化后显示图像。

    <img *ngIf="weatherClass" src="{{ './assets/icons/weather/' + weatherClass.img + '.svg' }}" width="130px" />
    

    【讨论】:

    • 您是否在img 上添加了*ngIf 指令?
    • 对不起,先生,我忘了添加*ngIf。非常感谢!
    猜你喜欢
    • 2020-12-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多