javascript - 如何以 Angular 修复 404(未找到)

标签 javascript angular

我收到错误 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/

相关文章:

javascript - 在 NVD3.js 中翻译鼠标悬停文本

angular - 带有去抖动的 BehaviorSubject 订阅

css - 更改所选选项卡的颜色,属于 TabMenu PRIMENG - 样式

angular - 'NgIf' 既不是 'ComponentType' 也不是 'DirectiveType'

javascript - Angular:将所有 FormControl 与模型更改同步

javascript - 用于 React 项目、Javascript 或 Node-js 的 Google API 客户端库?

javascript - 将 onhover 更改为 onclick

javascript - 如何在css中分离过滤器的不同属性?

javascript - 给定依赖项列表,如何将 Dojo 构建到单个文件中?

css - IONIC 4 ion-content 内滚动滚动条颜色/主题 w/Electron 应用程序