angular2从`[ngTemplateOutlet]`返回"<template>"数据

fxc*_*xck 6 angular

所以我有一个组件 <template>

<some-component [data]="someArray">
  <template>foo<template>
</some-component>
Run Code Online (Sandbox Code Playgroud)

并且它正在使用它来获取模板

@ContentChild(TemplateRef)
public tmpl: TemplateRef<any>;
Run Code Online (Sandbox Code Playgroud)

然后在它的模板中使用它

<div *ngFor="let item of someArrayFromDataInput">
  <template [ngTemplateOutlet]="tmpl"></template>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我希望能够从item原始模板中打印一些数据,基本上能够做到这一点

<some-component [data]="someArray">
  <template>foo {{ item }}<template>
</some-component>
Run Code Online (Sandbox Code Playgroud)

有可能吗?

fxc*_*xck 12

更新以匹配Angular 5+ api ngOutletContext已重命名ngTemplateOutletContext/sf/answers/2635785421/


一旦这个登陆https://github.com/angular/angular/pull/9042它会像这样工作

<div *ngFor="let item of someArrayFromDataInput">
  <template 
    [ngTemplateOutletContext]="{
      item: item
    }" 
    [ngTemplateOutlet]="tmpl"></template>
</div>
Run Code Online (Sandbox Code Playgroud)

+

<some-component [data]="someArray">
  <template let-item="item">foo {{ item }}<template>
</some-component>
Run Code Online (Sandbox Code Playgroud)

//编辑:登陆