【问题标题】:Angular ng build --aot giving template parse errorsAngular ng build --aot 给出模板解析错误
【发布时间】:2017-09-12 18:23:16
【问题描述】:

使用以下选项构建基于 Angular 4 的项目时出错,

ng build --aot 或按照此处的文档 (https://angular.io/guide/aot-compiler)

错误就像,

  1. 无法绑定到“ngIf”,因为它不是“div”的已知属性。
  2. 无法绑定到“routerLink”,因为它不是“a”的已知属性。
  3. 无法绑定到“ngIf”,因为它不是“li”的已知属性。

是否有任何解决方法或解决方案?

【问题讨论】:

    标签: angular


    【解决方案1】:

    您可能缺少Browser Module,请检查您是否已导入。

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

    routerLink 可能是同样的情况,缺少 RouterModule

    BrowserModule 应该导入到app.module 中,在所有其他模块中你应该导入CommonModule

    【讨论】:

    • 根据documentation:如果你正在编写一个浏览器应用程序,你应该从@angular/platform-browser而不是CommonModule导入BrowserModule。但除此之外,你是对的,这就是缺少的。
    • 没有帮助。仍然得到同样的东西。
    • 你能分享一些代码吗?您尝试使用的组件是什么样的?
    • 我有一个文件 common-modules.ts,其中我将所有常见模块作为 const 数组放入其他模块中。比如, export const commonModules = [RouteModule, BrowserModule, ...] 在我的模块中我使用的是 @NgModule({ import: commonModules.contact([EntityModule])})
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    相关资源
    最近更新 更多