angular2 ng-container如何使用动态ngTemplateOutletContext

前端之家收集整理的这篇文章主要介绍了angular2 ng-container如何使用动态ngTemplateOutletContext前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用ng-container和NgTemplateOutlet( https://angular.io/docs/ts/latest/api/common/index/NgTemplateOutlet-directive.html)

<div *ngFor="let child of children; let i=index">
      <ng-container *ngTemplateOutlet="inputTpl; { $implicit: child,index: i }"></ng-container>
  </div>

这会导致错误

Unexpected token {,expected identifier,keyword,or string at column 11 in [inputTpl; { $implicit: child,index: i }]

当我在文档中使用’context:’时,这会导致

Can’t bind to ‘ngTemplateOutletContext’ since it isn’t a known property of ‘ng-container’

如果我使用在我的ts文件中声明的对象并设置它而不是我的对象,一切都运行正常.此外,这也很好:

<div *ngFor="let child of children; let i=index" class="form-group">
      <template [ngTemplateOutlet]="inputTpl" [ngOutletContext]="{ $implicit: child,index: i }" />
    </div>

有谁知道,我如何使用带有* ngTemplateOutlet的ng-container和html中生成的ngTemplateOutletContext?

解决方法

你试过< ng-container>和[ngTemplateOutletContext]这样?

<ng-container
    [ngTemplateOutlet]="inputTpl"
    [ngTemplateOutletContext]="{ $implicit: child,index: i }"
>
</ng-container>

猜你在找的Angularjs相关文章