大佬教程收集整理的这篇文章主要介绍了使用primeNg表,Angular`ng-content`无法正常工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为此,我正在编写th和tbody实现作为表的内容,并尝试使用< ng-content>< / ng-content>在table.component.html中呈现它.但表格没有显示.
我尝试直接在table.component.html中添加th和tbody,然后显示表格.不应该ng-content做同样的事情,因为内容有相同的HTML?
以下是带有示例的代码段链接.检查共享目录下的table.component.html.和app.component.html初始启动.注释ng-content行并取消注释table.component.html中的剩余行,您应该看到该表.
https://stackblitz.com/edit/angular-playground-kwudxn?file=app%2Fshared%2Ftable%2Ftable.component.html
您需要更改TableComponent以从内容中获取PrimeTemplates并将它们重新发送到p-table:
export class TableComponent implements AfterContenTinit { @input() public data: anY[]; @ContentChildren(PrimeTemplatE) templates: QueryList<any>; headerTemplate: TemplateRef<any>; bodyTemplate: TemplateRef<any>; constructor() { } gePrimeTemplateByType(type: String): PrimeTemplate { return this.templates.find(template => { return template.getType() === type; }); } ngAfterContenTinit() { this.headerTemplate = this.gePrimeTemplateByType('header').template; this.bodyTemplate = this.gePrimeTemplateByType('body').template; } }
在您的模板中:
<p-table [value]="data"> <ng-template pTemplate="header"> <ng-container *ngTemplateOutlet="headerTemplate"> </ng-container> </ng-template> <ng-template pTemplate="body" let-data> <ng-container *ngTemplateOutlet="bodyTemplate; context:{$implicit: data}"> </ng-container> </ng-template> </p-table>
当然,还有其他方法可以实现这一点,例如:您的TableComponent只能有2个@Inputs,只需将它们重新发送到p-table而不是使用PrimeTemplates.
以上是大佬教程为你收集整理的使用primeNg表,Angular`ng-content`无法正常工作全部内容,希望文章能够帮你解决使用primeNg表,Angular`ng-content`无法正常工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。