我有一个弹出组件,我想将任何自定义组件注入其中。目前我正在使用 [innerHTML],但它无法呈现任何自定义组件。我 https://angular.io/guide/dynamic-component-loader 阅读了这篇文章,但无法使用它来实现。所以请提出建议。
popup.component.ts
<p-dialog [(visible)]="display" [responsive]="true" [blockScroll]=true (onHide)="onHide($event)" [width]="width" [resizable]="false">
<p-header>
<i>{{ title }}</i>
</p-header>
<div [innerHtml]="content|sanitizehtml"></div>
<p-footer>
<button type="button" pButton icon="pi pi-close" (click)="buttonClick($event)" [label]="noLabel" class="ui-button-secondary"></button>
<button type="button" pButton icon="pi pi-check" (click)="buttonClick($event)" [label]="yesLabel"></button>
</p-footer>
</p-dialog>
app.componet.ts
openLookup(e){
this.display = true;
this.title = 'Product ID';
this.content = `<p-checkbox [(ngModel)]="someFlag" binary="true" (onChange)="changedRow()"></p-checkbox>
<p-calendar name="endDate" [(ngModel)]="endDate" [monthNavigator]="true" [yearNavigator]="true" yearRange="1990:3000" [disabledDays]="[0,6]" [showIcon]="true" styleClass="full-width" inputStyleClass="calender-width">
</p-calendar>`;
}
尝试将弹出的HTML内容维护为子组件
您还可以与选择属性一起使用
父组件:
<child-component>
<div sample>Parent Content</div>
</child-component>
子组件:
...
<ng-content select="[sample]"></ng-content>
...
输出:
...
<div>Parent Content</div>
...
您也可以尝试使用ng-container