Angular 从TemplateRef获取属性

Angular 从TemplateRef获取属性,angular,Angular,我试图从元素中获取属性,但“template.elementRef.nativeElement”是无效的 。 这是我的代码: //父模板 {{row.startDate | date} //子模板 @ContentChildren(“列”)模板:QueryList; ngAfterContentInit(){ //这是我的问题 this.templates[''u results'].foreach(x=>this.columns[“columnId”].template=x); } 只需创建

我试图从元素中获取属性,但“template.elementRef.nativeElement”是无效的

这是我的代码:

//父模板
{{row.startDate | date}
//子模板
@ContentChildren(“列”)模板:QueryList;
ngAfterContentInit(){
//这是我的问题
this.templates[''u results'].foreach(x=>this.columns[“columnId”].template=x);
}

只需创建指令即可,即:

@Directive({
    selector: 'ng-template[column]',
})
然后您将有权访问指令实例:

@ContentChildren(TableColumnDirective)
public columnDirectives:QueryList<TableColumnDirective>;
@ContentChildren(TableColumnDirective)
公共列指令:QueryList;

您希望获得什么属性?
元素仅存在于角度范围内。它从未添加到DOM中,在运行时也不是元素。请给出一个示例,说明您试图实现的目标:自定义mat表、呈现defult模板,如果存在特殊模板,则呈现特殊模板。