无法绑定到"ngOutletContext",因为它不是"ng-template"的已知属性 [英] Can't bind to 'ngOutletContext' since it isn't a known property of 'ng-template'
问题描述
以下在Angular 4中效果很好
Below worked fine in 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抱怨这个错误:
Angular 5 is whining about this error:
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
没有任何关联.
Looking through the upgrade steps: https://angular-update-guide.firebaseapp.com/, I don't seem to have anything related to the ng-template
thing.
另外,那是我使用<ng-template></ng-template>
我该如何处理?
推荐答案
从v4开始不推荐使用
ngOutletContext
.在角度5中使用ngTemplateOutletContext
代替ngOutletContext
ngOutletContext
has been removed as it was deprecated since v4. UsengTemplateOutletContext
instead ofngOutletContext
in angular 5
检查此内容: https://github.com/angular/angular/blob/master/CHANGELOG.md#500-beta5-2017-08-29
并根据需要进行讨论:无法使ngTemplateOutlet正常工作
and take this discussion if you want: Can't get ngTemplateOutlet to work
这篇关于无法绑定到"ngOutletContext",因为它不是"ng-template"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!