【问题标题】:Can't bind to 'ngOutletContext' since it isn't a known property of 'ng-template' [duplicate]无法绑定到“ngOutletContext”,因为它不是“ng-template”的已知属性[重复]
【发布时间】:2017-11-10 10:50:59
【问题描述】:

以下在 Angular 4 中运行良好

<ng-container *ngFor="let user of list_users">
  <div *ngIf="currentUser.username !== user.username">
    <div class="card">
      bla bla
    </div>
  </div>
</ng-container>

Angular 5 抱怨这个错误:

Can't bind to 'ngOutletContext' since it isn't a known property of 'ng-template'.
1. If 'ngOutletContext' is an Angular directive, then add 'CommonModule' to the '@NgModule.imports' of this component.
2. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
        <!-- CUSTOM TEMPLATE -->
        <ng-template
            [ERROR ->][ngOutletContext]="{ item: model, index: index }"
            [ngTemplateOutlet]="template">
        "): ng:///TagInputModule/TagComponent.html@12:12
Property binding ngOutletContext not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("div *ngSwitchCase="true" [attr.contenteditable]="editing">
        <!-- CUSTOM TEMPLATE -->
        [ERROR ->]<ng-template
            [ngOutletContext]="{ item: model, index: index }"
            [ngTemplateOut"): ng:///TagInputModule/TagComponent.html@11:8
    at syntaxError (compiler.js:466)
    at TemplateParser.parse (compiler.js:24314)
    at JitCompiler._parseTemplate (compiler.js:33701)
    at JitCompiler._compileTemplate (compiler.js:33676)
    at eval (compiler.js:33578)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:33578)
    at eval (compiler.js:33448)
    at Object.then (compiler.js:455)
    at JitCompiler._compileModuleAndComponents (compiler.js:33447)

查看升级步骤:https://angular-update-guide.firebaseapp.com/,我似乎没有任何与ng-template 相关的东西。

另外,这是我在代码中唯一使用&lt;ng-template&gt;&lt;/ng-template&gt;的地方@

我该怎么做?

【问题讨论】:

  • 这个问题已经在meta上提到过。 /cc @GünterZöchbauer。
  • 所以我花时间深入研究错误。我正在使用第三方包(ngx-chips),它仍在使用已弃用的 angular5 抱怨的任何内容。更新包修复了错误。 github.com/Gbuomprisco/ngx-chips/issues/593

标签: angular angular5


【解决方案1】:

ngOutletContext 已被删除,因为它自 v4 以来已被弃用。在角度 5 中使用 ngTemplateOutletContext 而不是 ngOutletContext

检查这个:https://github.com/angular/angular/blob/master/CHANGELOG.md#500-beta5-2017-08-29

如果你愿意,可以参加这个讨论:Can't get ngTemplateOutlet to work

【讨论】:

  • :D 被自己替换了?我想你忘了#outletContext
  • @GünterZöchbauer 我已经更新了我的答案;我只是从我提到的链接中复制的NgTemplateOutlet#ngOutletContext has been removed as it was deprecated since v4. Use NgTemplateOutlet#ngTemplateOutletContext instead:P
  • Angular 6 和 7 的更新是什么?未找到 ngTemplateContext 和 ngTemplateOutletContext。将context = x 链接到*ngTemplateOutlet 也无济于事
猜你喜欢
  • 2019-05-19
  • 2018-02-12
  • 2016-03-17
  • 2021-06-16
  • 2021-03-20
  • 2021-10-24
  • 2017-02-05
  • 1970-01-01
相关资源
最近更新 更多