【问题标题】:Angular 9.0.5 can't bind ngIf and ngForAngular 9.0.5 无法绑定 ngIf 和 ngFor
【发布时间】:2020-09-28 01:48:12
【问题描述】:

我已经在我的一个组件中导入了 CommonModule 和 BrowserModule,它工作正常,但是当我尝试在其他组件视图中执行 *ngIf 时,它不起作用并且 Google 控制台向我显示此警告 core.js: 8046 无法绑定到“ngIf”,因为它不是“div”的已知属性(因为在 div 中我使用了 *ngIf)。我认为这是 angular 版本,但我还没有解决方案。

【问题讨论】:

    标签: angular


    【解决方案1】:

    BrowserModule应该在app模块中导入,在其他模块中,CommonModule应该被导入。

    所以在你的应用模块中:

    import { BrowserModule } from '@angular/platform-browser'
    
    ...
    @NgModule({
      imports: [BrowserModule],
      ...
    })
    

    【讨论】:

    • 感谢您的回复,我已经全部导入了,但是我有一个“管理布局模块”,我在其中导入了我的组件,我忘了在这里添加组件,它已经解决了。
    猜你喜欢
    • 2020-06-21
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    相关资源
    最近更新 更多