Angujar2,如何读取字符串中的组件?
测试组件(导演)
部分:app-test
主要组成部分 html:
<app-test>text</app-test>
我想要获取内心文本......
答案 0 :(得分:0)
使用<ng-content></ng-content>
@Component({
selector: 'app-test',
template: `<ng-content></ng-content>`,
})
获取变量中的内容
export class AppTestComponent {
content;
constructor(private elementRef: ElementRef) {
}
ngOnInit() {
this.content = this.elementRef.nativeElement.innerHtml;
}
}