Angular 2 bind transcluded content to loop variable

后端 未结 1 1511
忘了有多久
忘了有多久 2020-12-17 20:17

I\'m trying to bind transcluded content to a variable inside of a component loop but I\'m unable to do so.

I\'ve looked at the PrimeNG\'s dropdowncompo

相关标签:
1条回答
  • 2020-12-17 20:44

    Update Angular 6

    ngOutletContext was renamed to ngTemplateOutletContext template should be ng-template

    See also https://github.com/angular/angular/blob/master/CHANGELOG.md#500-beta5-2017-08-29

    Original

    You can get the template reference and add it using for example ngTemplateOutlet or ngForTemplate to get the template content added to the DOM. With ngTemplateOutlet you can provide your own context that you then can access with template variables as you tried.

    class CompComponent {
      context = {option: 'some option'};
      constructor(private templateRef:TemplateRef){}
    }
    
    <ng-template [ngTemplateOutlet]="templateRef" [ngOutletContext]="{$implicit: context}"></ng-template>
    

    I think in newer versions this needs to be

    <ng-template [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="{$implicit: context}"></ng-template>
    

    (but haven't yet verified)

    See also

    • How to repeat a piece of HTML multiple times without ngFor and without another @Component
    • Angular2 child component as data
    0 讨论(0)
提交回复
热议问题