【问题标题】:Can't bind to 'ngTemplateOutlet' since it isn't a known property of 'ng-container'无法绑定到“ngTemplateOutlet”,因为它不是“ng-container”的已知属性
【发布时间】:2021-06-16 16:37:08
【问题描述】:

这似乎是“@angular/common”模块和 ivy 编译器的问题?有任何想法吗? 删除node_modules并更新angular没有任何成功。

        <!-- Define our template -->
        <ng-template #myTemplate> World! </ng-template>

        Hello
        <!-- Render the template in this outlet -->
        <ng-container [ngTemplateOutlet]="myTemplate"></ng-container>

如果我尝试 ...*ngTemplateOutlet=... 那么我在运行时收到此错误:NG0303:无法绑定到“ngTemplateOutlet”,因为它不是“ng-container”的已知属性。 node_modules/@angular/core/ivy_ngcc/fesm2015/core.js:10073

Angular 版本 11

【问题讨论】:

  • 您是否将CommonModule 导入到您的项目中?
  • 感谢您的回复。我已导入应包含 CommonModule 的 BrowserModule?如果我导入 CommonModule implcit,也没有变化。
  • 如果我尝试导入 NgTemplateOutlet 我得到错误:node_modules/@angular/common/common.d.ts:2116:22 - 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但可以不能解析为 NgModule 类。这可能意味着声明 NgTemplateOutlet 的库(@angular/common)没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还可以考虑与图书馆的作者核实,看看图书馆是否应该与 Ivy 兼容。
  • 如果我做一个空白应用程序(ng new app-name)它可以工作。但是,如果我使用 DevExtreme 模板(“npx -p devextreme-cli devextreme new angular-app app-name”),我可以重现该错误。我还询问了 DevExpress 支持。所以这可能是他们的库的问题。我会及时通知你!

标签: angular ivy ngtemplateoutlet


【解决方案1】:

这是在 DevExtreme 模板中混淆了 app.module.ts(实际上是导入了BrowserModule)和 app-routing.module.ts。 在我将BrowserModule 中的app-routing.module.ts 添加到@NgModule({ imports: 之后,它按预期工作。 @Ilia Komarov:谢谢!您的解决方案也是正确的!

【讨论】:

    猜你喜欢
    • 2021-03-20
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 2018-08-29
    • 1970-01-01
    • 2017-06-21
    相关资源
    最近更新 更多