大佬教程收集整理的这篇文章主要介绍了angular – 访问被抄送的内容,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<gs-code> console.log("Asd")</gs-code>
该组件看起来像这样
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>
如何在组件中获取已转换的文本?
我已尝试将contentChild和#content用作< ng-content#content>< / ng-content>.但这些都没有奏效.
然后你可以得到包装元素的innerHTML
@Component({ SELEctor: 'item',template: '<div #wrapper><ng-content></ng-content></div>'}) class Item implements AfterContenTinit { @ViewChild('wrapper') wrapper:ElementRef; @input() type:string = "type-goes-here"; ngAfterContenTinit() { console.log(this.wrapper.nativeElement.innerHTML); // or `wrapper.text` } }
以上是大佬教程为你收集整理的angular – 访问被抄送的内容全部内容,希望文章能够帮你解决angular – 访问被抄送的内容所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。