简体   繁体   English

无法绑定到“ ngFor”,因为它不是已知的本机属性

[英]Can't bind to 'ngFor' since it isn't a known native property

Hey I know this question comes up a lot but the normal fixes do not work. 嘿,我知道这个问题很多,但是正常的修复方法不起作用。 I tried the # way of typing and much more. 我尝试了#打字方式等等。 Here is my code: 这是我的代码:

<table>
   <tr>
     <th>Name</th>
     <th>Desc</th>
     <th>Time est</th>
   </tr>
   <div *ngFor="let ToDo of toDoArray">
   <tr>
     <td>{{ToDo.Name}}</td>
     <td>{{ToDo.Desc}}</td>
     <td>{{ToDo.Time}}</td>
   </tr>
   </div>
   </table>

It is a table in a table that needs to walk through all the ToDo's in the array toDoArray. 它是一个表中的表,需要遍历数组toDoArray中的所有ToDo。 Here is my contructor: 这是我的建设者:

    constructor(){
    this.toDoArray.push(
        new ToDo("The name","You know", "20 min")
);
}

I added a Plukr 我加了一个Plukr

Put the iteration in the tr instead, I guess that is what you want to achieve :) 取而代之的是将迭代放入tr ,我想这就是您想要实现的目标:)

<table>
   <tr>
     <th>Name</th>
     <th>Desc</th>
     <th>Time est</th>
   </tr>
   <tr *ngFor="let ToDo of toDoArray">
     <td>{{ToDo.Name}}</td>
     <td>{{ToDo.Desc}}</td>
     <td>{{ToDo.Time}}</td>
   </tr>
</table>

EDIT: 编辑:

Remember to initialize the array in the beginning, like: private toDoArray : ToDo[] = []; 请记住在开始时要初始化数组,例如: private toDoArray : ToDo[] = []; That should solve (problem), not knowing if you get to see any results in your table at all, but if you do get to see some values in your table... 那应该解决(问题),完全不知道您是否可以在表中看到任何结果,但是如果您确实可以看到表中的某些值...

The reason why your template is all messed up, is because you are somehow trying to nest the tables, that just results in a hot mess like you have going on there. 之所以将模板全部弄乱,是因为您以某种方式试图嵌套表格,这只会像您在其中那样造成混乱。 I see you want to separate ToDo's based on their status. 我看到您想根据其状态来区分待办事宜。 Just make them 3 separate tables and you are good to go, that would be my suggestion! 只需将它们做成3张单独的桌子,您就可以使用了,这就是我的建议! :) :)

Your forked plunker with the above changes. 通过上述更改,您的分叉式拨弹车

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “无法绑定到&#39;ngFor&#39;,因为它不是已知的本机属性” - “Can't bind to 'ngFor' since it isn't a known native property” 无法绑定到“*ngFor”,因为它不是“div”的已知属性 - Can't bind to '*ngFor' since it isn't a known property of 'div' 例外:无法绑定到“ngFor”,因为它不是已知的本机属性 - Exception: Can't bind to 'ngFor' since it isn't a known native property |官方指南坏了吗?| 无法绑定到“ ngFor”,因为它不是已知的本机属性 - |Official guide broken?| Can't bind to 'ngFor' since it isn't a known native property 无法绑定到&#39;href&#39;,因为它不是已知的本机属性 - Can't bind to 'href' since it isn't a known native property 无法绑定到&#39;ngFormControl&#39;,因为它不是已知的本机属性 - Can't bind to 'ngFormControl' since it isn't a known native property 无法绑定到“formGroup”,因为它不是已知的本机属性 - Can't bind to 'formGroup' since it isn't a known native property 无法绑定到“ ngValue”,因为它不是已知的本机属性” - Can't bind to 'ngValue' since it isn't a known native property" Angular:ngFor中的三元运算符抛出错误无法绑定到“ ngFor”,因为它不是“ div”的已知属性 - Angular: ternary operator in ngFor throw error Can't bind to 'ngFor' since it isn't a known property of 'div' Angular 2 RC5:无法绑定到&#39;ngFor&#39;,因为它不是已知的属性 - Angular 2 RC5: Can't bind to 'ngFor' since it isn't a known property of
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM