我正在努力在primeng包的“p-dialog”部分添加复选框。但是,我遇到了 UI 问题,当我尝试从 UI 手动取消选中复选框时,它也不起作用,更改或单击事件也不会触发。在与复选框相关的部分代码下方发布。有人可以建议需要修复什么才能使其正常工作。
html代码
<p-dialog modal="modal" width="600" [responsive]="true" [closable]="false">
<p-header>
<span>Dialog</span>
</p-header>
<input type="checkbox" [name]="chkMyself" [id]="chkMyself" (change)="toggleVal($event)" >
<label for="chkMyself">Myself</label>
</p-dialog>
组件代码
import { Component, Output,ViewChild, EventEmitter, ViewEncapsulation } from '@angular/core';
import { Dialog } from 'primeng/primeng';
@Component({
selector: 'app-dialog',
templateUrl: './app-dialog.component.html',
styleUrls: ['./app-dialog.component.scss']
})
export class AppDialogComponent {
@ViewChild(Dialog) public theDialog: Dialog;
public dialogTitle: string;
public chkMyself: boolean = false;
constructor( ) {
}
private _display: boolean = false;
get Display(): boolean {
return this._display;
}
set Display(val: boolean) {
this._display = val;
if(val){
this.show("Dialog Test");
}
}
public toggleVal(event): void {
debugger
this.chkMyself = !event.target.checked;
}
public show(dialogTitle: string)
{
this.dialogTitle = dialogTitle;
this.theDialog.visible=true;
}
}