Angujar2,如何读取字符串中的组件?

时间:2017-05-11 01:19:30

标签: angular

Angujar2,如何读取字符串中的组件?

测试组件(导演)

部分:app-test

主要组成部分 html:

<app-test>text</app-test>

我想要获取内心文本......

1 个答案:

答案 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;
   }
}