当响应中的标识符之一是 Angular 应用程序中的数字时,我应该如何实现模型接口
How should I implement the model interface when one of the identifiers in the response is a number in an Angular app
来自 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: Parser Error: Unexpected token '0.48' at column 14 in [{{ trailer.data.480 }}]
如何解决这个问题?
另外,当出现问号时,我该如何修复 {{ trailer.data?['480'] }}
谢谢
你试过吗{{ trailer.data['480'] }}
来自 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: Parser Error: Unexpected token '0.48' at column 14 in [{{ trailer.data.480 }}]
如何解决这个问题?
另外,当出现问号时,我该如何修复 {{ trailer.data?['480'] }}
谢谢
你试过吗{{ trailer.data['480'] }}