我不能迭代对象数组。在每个对象中,我都有一个名称,但我无法获取对象的文本或其中的名称。
我的ts文件中有以下代码
retrieveMultiple(config, "accounts")
.then(
(results) => {
const accounts: any[] = [];
for (let record of results.value) {
accounts.push(record);
}
this.accounts= accounts;
console.log(accounts[0].name);
console.log(accounts);
},
(error) => {
console.log(error);
}我的HTML文件中有以下内容:
<p>Accounts:</p>
<ul>
<li *ngFor="let account of accounts | json">
{{ account.name }}
</li>
</ul>发布于 2019-03-03 05:18:14
循环表达式中不应包含json管道。将您的输出代码更改为:
<p>Accounts:</p>
<ul>
<li *ngFor="let account of accounts">
{{ account.name }}
</li>
</ul>或者,对于调试,您可以使用以下命令:
<p>Accounts:</p>
<ul>
<li *ngFor="let account of accounts">
{{ account | json }}
</li>
</ul>发布于 2019-03-03 05:19:46
https://angular.io/api/common/NgForOf
retrieveMultiple(config, "accounts")
.then(
(results) => {
this.accounts = results.value;
console.log(this.accounts[0].name);
console.log(this.accounts);
},
(error) => {
console.log(error);
}
)<p>Accounts:</p>
<ul>
<li *ngFor="let account of accounts">
{{ account.name }}
</li>
</ul>https://stackoverflow.com/questions/54963025
复制相似问题