Angular2 编译器-cli 无法识别 [ngClass] 或 *ngIf

标签 angular

我想使用最新版本的 Angular 离线编译器提前编译。我将所有必需的软件包更新到了​​ RC5,拥有最新版本的编译器等。

但是后来我遇到了一堆错误,例如:

  • 无法绑定(bind)到“ng-class”,因为它不是“div”的已知属性。
  • 无法绑定(bind)到“ngIf”,因为它不是“div”的已知属性。
  • 属性绑定(bind) ngIf 未被嵌入模板上的任何指令使用。确保属性名称拼写正确并且 所有指令都列在“指令”部分中。
  • 无法绑定(bind)到“ngClass”,因为它不是“my-component”的已知属性。

我从 http://www.syntaxsuccess.com/viewarticle/offline-compilation-in-angular-2.0 注意到可能需要在 @Component 装饰器中包含通用指令。但看起来这个问题自 RC5 以来已得到修复:https://github.com/angular/angular/blob/master/CHANGELOG.md 。当我尝试这样做时遇到的错误似乎表明不再需要这样做:

Type NgIf is part of the declarations of 2 modules: CommonModule and AppModule!

我还可以使用 tsc 和 RC5 正常编译和运行该站点,因此这不是升级问题。所以我完全不知道是什么导致了这些错误。

非常感谢任何帮助。

最佳答案

解决方案非常简单。我只是在 AppModule 中的 @NgModule 导入中缺少 BrowserModule。

关于Angular2 编译器-cli 无法识别 [ngClass] 或 *ngIf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38922138/

相关文章:

angularjs - 如何正确地将node_modules移动到不同的位置

angular - 模块解析失败 : Parenthesized pattern You may need an appropriate loader to handle this file type

Angular 2 - 使导入的模块可以在子模块中访问

Angular + Material - 如何在表格中添加自定义列(Mat-Table)

angular - 无法绑定(bind)到 'disabled',因为它不是 'li' 的已知属性

html - 无法通过 btn-group open 打开下拉按钮组

javascript - Angular2 导入语法 : "import * as <foo>" vs "import {<foo>}"

javascript - ngmodelchange 在 Angular 6 Material 中调用了两次

javascript - Angular Material : How to select a specific mat-cell in mat-table?

angular - 如何使用 Angular 4 上下文菜单