I have converted Angular 4 to Angular 6 and I have built the project and geting the following error. Any idea how to handle?
Can't bind to 'ngTemplateOutletContext' since it isn't a known property of 'ng-container'.
<ul *ngIf="item.childrens != undefined && item.childrens.length > 0">
<ng-container *ngTemplateOutletContext="recursiveList; context:{ $implicit: item.childrens }"></ng-container>
</ul>
My question is on TemplateOutletContext
, not TemplateOutlet
.
This likely means that the library (@angular/common) which declares NgTemplateOutlet has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so.
ngTemplateOutlet is a structural directive. We use it to insert a template (created by ngTemplate ) in various sections of our DOM. For example, you can define a few templates to display an item and use them display at several places in the View and also swap that template as per the user's choice.
A context object to attach to the EmbeddedViewRef . This should be an object, the object's keys will be available for binding by the local template let declarations. Using the key $implicit in the context object will set its value as default. @Input() ngTemplateOutlet: TemplateRef<any> | null.
You can define local variables on ng-template through let-name. When angular creates a template by calling createEmbeddedView it can also pass context that will be used inside ng-template. Using the key $implicit in the context object will set its value as default.
As per the docs:
ngTemplateOutletContext
bound toNgTemplateOutlet.ngTemplateOutletContext
So you would be able to attach context in the following way:
<ng-container
[ngTemplateOutlet]="recursiveList"
[ngTemplateOutletContext]="{ $implicit: item.childrens }"></ng-container>
Or:
<ng-container *ngTemplateOutlet="recursiveList; context: { $implicit: item.childrens }"></ng-container>
Angular needs to know what view you intend on adding your context object to, so ngTemplateOutletContext
won't work on its own AFAIK.
Source, Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With