javascript - Angular 2无法在html页面中显示项目列表

标签 javascript angular angular2-template

又是我......我在 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/

相关文章:

angular - 如何计算从现在到 Angular 中声明的一天之间的总天数?

Angular 2 - 使用 ngStyle 将背景图像转换为 html 文件

javascript - JS 源在 Chrome/Firefox 调试器中不可见,但在页面中正确加载

javascript - Mysql AES_ENCRYPT => 客户端 JavaScript Aes.Ctr.decrypt 问题

javascript - Impress.js 和使用 HTML5 数据属性代替 CSS 转换

typescript - 什么是 Angular 2 中的 `change` 事件

angular - Ionic2 Ion-select 没有 OK 和 Cancel

angular - 如何将配置传递到 angular-cli 中的 indexTransform 中?

html - 按钮内图像的动画

javascript - 如何在 Angular 中将子组件的@inputs 和@outputs 隐式公开给祖 parent ?