2
我有我使用以显示其在组件访问transcluded内容
<gs-code> console.log("Asd")</gs-code>
组件看起来像这样
code.component.ts transcluded的代码块中的组元
@Component({
selector: 'gs-code',
providers: [],
viewProviders: [],
templateUrl: './code.component.html',
styleUrls: ['./code.component.less']
})
export class GsCodeComponent {
@Input() lang: string;
@Input() currentLang: string;
@ContentChild('content') content;
copied(event) {
console.log(event);
}
ngAfterContentInit() {
console.log(this.content, "content");
}
}
code.component.html
<pre class="prettyprint">
<ng-content #content></ng-content>
</pre>
<button class="btn btn-sm" title="Copy to clipboard" (click)="copied(content.innerHtml)"><i class="fa fa-clipboard"></i></button>
如何获取组件中的横向文本? 我试过使用contentChild
和#content
作为<ng-content #content></ng-content>
。但这些都没有奏效。
的DUP http://stackoverflow.com/questions/37573439/get-component-child-as-的
innerHTML
串/ 37586026#37586026 –