【发布时间】:2017-10-19 07:58:36
【问题描述】:
我在 angular 2 应用程序中使用primeng,并面临这个问题(stackoverflow question)
虽然在接受的答案中提供的 plunkr 有效,但在我的场景中却没有。我有一个单独的组件,它根据父组件的输入加载。我想在子组件关闭/隐藏时切换可见性标志。
这里是代码 sn-p
<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 我在下面添加了关于我如何做到这一点的答案。
标签: angular angular2-template primeng