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

时间:2019-11-05 07:10:41

标签: angular

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>

2 个答案:

答案 0 :(得分:1)

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

如果仍然无法解决,请尝试通过在 tsconfig.app.json 文件

中将以下布尔值设置为false来禁用IVY引擎
"enableIvy": false

并在 angular.json 文件中,删除aot

"aot": true

答案 1 :(得分:0)

确保在let内添加一个*ngFor关键字。即使您已经将模块导入app.module.ts

中,您也可能会错过该模块
<h2>My Data</h2>
<ul>
  <li *ngFor="let d of data">{{ d.name }}</li>
</ul>