又是我......我在 View 中显示项目数组时遇到问题,我总是收到此错误。 [未处理的 Promise 拒绝:无法设置 undefined 的属性“stack”;区域: ;任务:Promise.then;值:类型错误:无法设置未定义的属性“堆栈”]
也许我在 html View 中绑定(bind)数据时做错了什么。
ngOnInit() : void{
this._loadCoil.getAllCoils().subscribe(coils =>{ this.coils = coils;
this.gridData = {
data: this.coils.slice(this.currentPage, this.currentPage + this.displaySize),
total: this.coils.length};
for(let i = 0; i < this.coils.length; i++){
let isFound = false;
for (let j = 0; j < this.dropDownArray.length; j++){
if (this.dropDownArray[j] == this.coils[i].unit){
isFound = true;
break;
}
}
if(!isFound){
this.dropDownArray.push(this.coils[i].unit);
}
}
});
}
基本上我想用单位名称填充数组并将其显示在网站上。 (这部分工作正常)
但是,当我想在页面上打印姓名时,我会得到前面提到的内容。这是我的 html 页面的代码片段
<div>
<ul>
<li *ngFor="let name in dropDownArray">{{name}}</li>
</ul>
</div>
最佳答案
迭代中应该是 of
,而不是 in
:
<li *ngFor="let name of dropDownArray">{{name}}</li>
关于javascript - Angular 2无法在html页面中显示项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41743821/