我使用primeng在角2应用程序和面对这个问题(stackoverflow question)对对话onHide没有角2组分工作 - primeng
虽然在接受答案的作品所提供的plunkr但它确实不是我的场景。我有一个单独的组件加载基于来自父组件的输入。我想在子组件关闭/隐藏时切换可见性标志。
下面的代码片段
<p-dialog header="Assets Management" [(visible)]="showDialog" modal="modal" [closable]="true" (onHide)="close()" appendTo="body">
.. some content ..
</p-dialog>
在分量,我有:
@Component({
selector: 'view-car-colors',
templateUrl: '/view-car-colors.html',
inputs: ['showDialog'],
outputs: ["onCloseDialog"],
})
export class ViewCarColorsComponent {
private showDialog: boolean = false; //default close
private onCloseDialog: EventEmitter<any> = new EventEmitter();
public close(): void {
this.showDialog = false;
//emit this to its parent
this.onCloseDialog.emit({ hasChanges: true });
}
}
最后,在我的父组件,我称它想:
<view-car-colors [showDialog]="showCarColorsDialog" (onCloseDialog)="onCarColorsCloseDialog($event)"></view-car-colors>
凡showCarColorsDialog
基于按钮点击而改变。
private onCarColorsCloseDialog($event: any): void {
this.showCarColorsDialog = false;
if ($event.hasChanges) {
//fetch the changes again
this.getCarColors();
}
}
我已经使用在多个地方primeng控制,他们都工作得很好,但只是有这个问题,所以我敢肯定,这不可能是因为版本。
是的,这是我的问题。你有没有找到解决方案? bcs仍然在为此而苦苦挣扎。 –
@RameshRajendran我添加了我的答案,我是如何在下面做的选择。 –