欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解决ERROR Error: Cannot find a differ supporting object ‘[object Object]‘

程序员文章站 2022-03-03 18:32:30
...

前提:最近新增一个标签html页面新增如下代码:

 <ng-container *ngFor="let item of this.secondLevelModalData">
        <li class="publish-li" (click)="publishClick(item)">
          <div class="publish-li-clicle">
            <img class="li-img" src="{{item.icon}}"
              onerror="this.src='assets/laijian/[email protected]'" />
          </div>
          <p class="li-p">{{item.label}}</p>
        </li>
      </ng-container>

结果页面报错:

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
    at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3368)
    at checkAndUpdateDirectiveInline (core.js:22102)
    at checkAndUpdateNodeInline (core.js:23363)
    at checkAndUpdateNode (core.js:23325)
    at debugCheckAndUpdateNode (core.js:23959)
    at debugCheckDirectivesFn (core.js:23919)
    at Object.eval [as updateDirectives] (SharePageComponent.html:127)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911)
    at checkAndUpdateView (core.js:23307)
    at callViewAction (core.js:23548)

原因是因为当前传入的参数是一个对象,改成数组即可。

像下面这样:

<ng-container *ngFor="let item of this.secondLevelModalData.data">
        <li class="publish-li" (click)="publishClick(item)">
          <div class="publish-li-clicle">
            <img class="li-img" src="{{item.icon}}"
              onerror="this.src='assets/laijian/[email protected]'" />
          </div>
          <p class="li-p">{{item.label}}</p>
        </li>
      </ng-container>