无法绑定到"ngForOf",因为它不是"div"的已知属性。何时在 HTML 文件中进行更改



ngFor在我运行ng-serve时运行良好。我可以很容易地导航到每一页,没有任何错误

**但是,当我更改像xyz.component.html这样的html文件中的任何一行时,应用程序成功编译,但在控制台中,我收到了错误。无法绑定到"ngForOf",因为它不是"div"的已知属性**

请给我一些解决方案。

<div class="dashboard row">
<div class="card col-lg-3" *ngFor="let card of cards">
<h5 class="card-title">{{card.title}}</h5>
<div class="card-body">
<ul style="list-style-type:none;">
<li *ngFor="let cardFeature of cardFeatures" style="padding-left: 7px;">
<a href="" *ngIf="cardFeature.enable" [routerLink]="cardFeature.link">{{cardFeature.title}}</a>    
<!-- <button type="submit>Submit</button> -->
</li>
</ul>
</div>
</div>

确保在最顶层模块(即app.module.ts(中导入了BrowserModule。所有子模块都将导入CommonModule

如果仍未解决,请尝试禁用IVY引擎,方法是在tsconfig.app.json文件中将以下布尔值设置为false

"enableIvy": false

angular.json文件中,删除aot

"aot": true

确保在*ngFor中添加let关键字。即使你已经在app.module.ts上导入了模块,你也可能会错过这个

<h2>My Data</h2>
<ul>
<li *ngFor="let d of data">{{ d.name }}</li>
</ul>

最新更新