从TemplateRef

时间:2017-10-17 14:41:40

标签: angular

我尝试从element获取属性,但“template.elementRef.nativeElement”是

<!--->.

这是我的代码:

  // Parent template
  <p-table  *ngIf="serias" [rows]="serias" [columns]="columns">
    <ng-template #column column="startDate" let-row="row">
      <div> {{row.startDate | date}}</div>
  </ng-template>
  </p-table>
  // child template
    @ContentChildren('column') templates : QueryList<any>;

        ngAfterContentInit() {
        // Here is my problem
            this.templates['_results'].foreEach(x => this.columns["columnId"].template = x);
        }

1 个答案:

答案 0 :(得分:1)

只需创建指令即:

@Directive({
    selector: 'ng-template[column]',
})

然后您将可以访问指令实例:

@ContentChildren(TableColumnDirective)
public columnDirectives:QueryList<TableColumnDirective>;