angularjs - 角度 ngFor 警告 - 只允许使用数组和可迭代对象
问题描述
需要帮助理解此错误消息,
在 UI 方面一切似乎都正常,所以我不确定为什么我会看到这个。
Error trying to diff '[object Object]'. Only arrays and iterables are allowed
这是 for 循环:
<tr *ngFor="let draft of drafts; let i = index">
<td width="1%">
<xerox-checkbox [(ngModel)]="draft.selected" ></xerox-checkbox>
</td>
<td>
code truncated.
和错误消息:
DraftsComponent.html:29 ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
at DefaultIterableDiffer.push../node_modules/@angular/core/fesm5/core.js.DefaultIterableDiffer.diff (core.js:5642)
at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3157)
at checkAndUpdateDirectiveInline (core.js:9246)
at checkAndUpdateNodeInline (core.js:10507)
at checkAndUpdateNode (core.js:10469)
at debugCheckAndUpdateNode (core.js:11102)
at debugCheckDirectivesFn (core.js:11062)
at Object.eval [as updateDirectives] (DraftsComponent.html:96)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:11054)
at checkAndUpdateView (core.js:10451)
草稿对象数组:
drafts[{"id":"1000019","printerName":"Regin1","printerState":"US","userId":"userId1","userEmail":null,"aaName":"","sale":null},
{"id":"1000018","printerName":null,"printerState":"US","userId":"userId2","userEmail":null,"aaName":"","sale":null},
{"id":"1000014","printerName":"my new entry","printerState":"US","userId":"userId4","userEmail":null,"aaName":"","sale":null}]
解决方案
在您使用的模板drafts[_].selected
上,但该属性在变量的分片日志中不存在。
你能提供更多细节吗?和/或一个https://stackblitz.com/玩?
我制作了一个最小的示例:
https ://stackblitz.com/edit/angular-ivy-zzdpk3?file=src/app/app.component.html
PS:什么是adp-checkbox
?我在谷歌上没有找到任何关于它的信息。
推荐阅读
- javascript - AmplifyJS 状态错误类型错误:无法读取未定义的属性“状态”
- angular - 更改路由物料表时闪烁
- javascript - 当文本匹配选择时支持输入框
- java - 根据持有的对象中是否存在值,在 Optional 中传递对象
- c# - 将带有联合的 C++ 结构编组到 C#
- reporting-services - 使用表达式隐藏基于参数的列
- flex-lexer - 在 flex/lex 中获取字符串 c 样式
- c++ - C++ std::threads 有预热期吗?
- linux - spark 作业在客户端模式下运行,但由于权限问题而不能在集群模式下运行
- javascript - 在本机反应中绘制垂直虚线