尝试从PrimeNG Library扩展对话框功能
显示对话框时出现错误,未显示时没有错误
this.containerViewChild未定义
我有什么
import { Component, Input, OnInit, Output, forwardRef } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { Dialog, DomHandler } from 'primeng/primeng';
const DIALOG_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => Dialog),
multi: true
};
@Component({
selector: 'sb-dialog',
providers: [DIALOG_VALUE_ACCESSOR, DomHandler],
template: ''
})
export class MyDialogComponent extends Dialog {
ngOnInit(): void {
}
}
目标: 请帮我解决此错误,并希望创建一个Dialog类的工作扩展。
答案 0 :(得分:0)
原来它不需要任何花哨的东西来复制模板。其他一切似乎只是通过扩展它来起作用
import { Component, Input, OnInit, Output, forwardRef, Inject, ElementRef,Renderer2, NgZone } from '@angular/core';
import { Dialog, DomHandler } from 'primeng/primeng';
@Component({
selector: 'sb-dialog',
providers: [DomHandler],
template: `
<div #container [ngClass]="{'ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow':true, 'ui-dialog-rtl':rtl,'ui-dialog-draggable':draggable}" [style.display]="visible ? 'block' : 'none'"
[ngStyle]="style" (scroll)="onScroll($event)" [class]="styleClass" [style.width.px]="width" [style.height.px]="height" [style.minWidth.px]="minWidth" [style.minHeight.px]="minHeight" (mousedown)="moveOnTop()" [@dialogState]="visible ? 'visible' : 'hidden'"
role="dialog" [attr.aria-labelledby]="id + '-label'">
<div #titlebar class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"
(mousedown)="initDrag($event)" *ngIf="showHeader">
<span [attr.id]="id + '-label'" class="ui-dialog-title" *ngIf="header">{{header}}</span>
<span [attr.id]="id + '-label'" class="ui-dialog-title" *ngIf="headerFacet && headerFacet.first">
<ng-content select="p-header"></ng-content>
</span>
<a *ngIf="closable" [ngClass]="{'ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all':true}" href="#" role="button" (click)="close($event)" (mousedown)="onCloseMouseDown($event)">
<span class="pi pi-times"></span>
</a>
</div>
<div #content class="ui-dialog-content ui-widget-content" [ngStyle]="contentStyle">
<ng-content></ng-content>
</div>
<div class="ui-dialog-footer ui-widget-content" *ngIf="footerFacet && footerFacet.first">
<ng-content select="p-footer"></ng-content>
</div>
<div *ngIf="resizable" class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"
(mousedown)="initResize($event)"></div>
</div>
`
})
export class MyDialogComponent extends Dialog {
ngOnInit(): void {
}
onScroll(evt) {
console.log(evt);
}
}