I have a componenet which i use to display a block of code which is transcluded in the component
<gs-code> console.log("Asd")</gs-code>
The component looks like this
code.component.ts
@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>
How can I get the transcluded text in the component?
I have tried using contentChild
and #content
as the <ng-content #content></ng-content>
. But these have not worked.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…