p-dialog onHide无法在角度2分量中工作-Primeng [英] p-dialog onHide not working in angular 2 component - primeng
问题描述
我在angular 2应用程序中使用primeng并面临此问题
I'm using primeng in an angular 2 application and facing this issue (stackoverflow question)
尽管接受的答案中提供的plunkr起作用,但在我的情况下却不起作用.我有一个单独的组件,该组件根据父组件的输入来加载.我想在子组件关闭/隐藏时切换可见性标志.
Although the plunkr provided in the accepted answer works but it doesn't in my scenario. I have a separate component that loads the based on an input from the parent component. I want to toggle the visibility flag when the child component is closed/hidden.
这是代码段
<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 });
}
}
最后在我的父组件中,我这样称呼它:
And finally in my parent component, I am calling it like:
<view-car-colors [showDialog]="showCarColorsDialog" (onCloseDialog)="onCarColorsCloseDialog($event)"></view-car-colors>
通过单击按钮更改showCarColorsDialog
的位置.
Where showCarColorsDialog
is changed based on a button click.
private onCarColorsCloseDialog($event: any): void {
this.showCarColorsDialog = false;
if ($event.hasChanges) {
//fetch the changes again
this.getCarColors();
}
}
我在多个地方都使用了primeng控件,它们都可以正常工作,但是有这个问题,所以我敢肯定不是因为版本.
I have used the primeng controls on multiple places and they all work fine but just has this issue so I'm sure it can't be because of the version.
推荐答案
尝试(onAfterHide)="close()"
.
https://github.com/primefaces/primeng/issues/956
这篇关于p-dialog onHide无法在角度2分量中工作-Primeng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!