当我单击材质表行时,我想将动态数据集绑定到垫对话框中的表,此处我的数据将绑定到垫对话框中,但是会产生一个问题,当我第一次单击row(whose id=1)
时它将在对话框中绑定null,类似,当我再次单击该行时row(whose id = 1)
,它将在对话框中绑定id = 1的数据,与id=3
,id=4
相同。
我的component.ts文件
items: any ;
getitemsbyorderid(orderid) {
this.orderservice.getitems(+orderid)
.subscribe(
items => {
this.items = items;
}, //Bind to view
err => {
// Log errors if any
console.log(err);
})
}
openDialog(address, city, pin, phone, orderid, orderstatus, totalprice,
updateby, updatedate): void {
this.userdata = JSON.parse(localStorage.getItem('currentUser'));
this.getitemsbyorderid(orderid);
const dialogRef = this.dialog.open(OrderDialogComponent, {
width: '1000px',
data: { Address: address, City: city, Pin: pin, phone: phone, Orderid:
orderid, Orderstatus: orderstatus, Totalprice: totalprice, Updateby:
updateby, Updatedate: updatedate, itemdata: this.items,Username:
this.userdata.user_name }
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
//this.animal = result;
this.ngOnInit();
});
}
在这里我在opendilog()内部调用this.getitemsbyorderid(orderid);
,它第一次返回null。当我单击第一行时,它绑定null,但是当我第二次单击该行时,它返回并绑定正确的数据,我想在第一次单击mat对话框时绑定特定的id值。