【发布时间】:2019-05-24 08:49:43
【问题描述】:
在 app.component.ts 我通过 API 接收数据:
export class AppComponent implements OnInit{
constructor(private http: HttpClient){}
items: Object;
getApi(){
return this.http.get("https://reqres.in/api/user");
}
ngOnInit(){
this.getApi().subscribe( data => {
this.items = data
console.log(this.items)
})
}
}
在我的 app.component.html 中,我输出了该数据:
<ul *ngIf="items">
<li *ngFor="let item of items.data">
{{ item.id }} {{ item.name }} {{ item.year }}
</li>
</ul>
我的问题是,是否可以使用连接到 id 整数的字符串来更改 id。 例如 id = 1 => 1 表示字符串“一”,id = 2 => 表示字符串“二”。
遗憾的是,我不知道如何将接收到的数据的值更改为新值。
我希望清楚我想要实现的目标,如果没有,请随时询问!
我希望你能帮助我。谢谢!
【问题讨论】:
-
你想把数字变成单词吗?
-
@Oen44 正确,这只是一个真实项目的示例。
标签: angular typescript api