首页 > 解决方案 > 当响应中的标识符之一是 Angular 应用程序中的数字时,我应该如何实现模型接口

问题描述

来自 api 的示例响应:

"results":[
      {
         "id":16228,
         "name":"ABCD",
         "preview":"/d8a/d8a61a3a12e52114afdbc28f2c813f5c.jpg",
         "data":{
            "480":"https://mdb.net/steam/6693661/movie480.mp4",
            "max":"https://mdb.net/steam/6693661/movie_max.mp4"
         }

我的界面如下:

interface Movie {
  data: {
    max: string;
    480: string;
  };
}

当我尝试

<video
        class="movie"
        controls
        *ngFor="let trailer of results"
      >
        <source src="{{ trailer.data.480 }}" <-------- Error here
         type="video/mp4" />
        Your browser does not support the video tag.
      </video>

NG5002:解析器错误:[{{ trailer.data.480 }}] 中第 14 列的意外令牌“0.48”

如何解决?

另外,当问号出现时,如何修复 {{ trail.data?['480'] }}

谢谢

标签: angularinterfaceresponsenumericangular12

解决方案


你试过吗{{ trailer.data['480'] }}


推荐阅读