在编辑和添加行时刷新组件
refresh component on edit and add row
我有一个父组件 AdsbyuserComponent,我需要使用 ag-grid 编辑或添加一行。
我已经设法将信息发送到服务器,但是在关闭弹出窗体时,我无法刷新 table。
这是我的代码
AdsbyuserComponent
update(ad :Ad) {
let ngbModalOptions: NgbModalOptions = {
backdrop : 'static',
keyboard : false ,
};
const modalRef = this.modalService.open(EditAdComponent,ngbModalOptions);
modalRef.componentInstance.ad = ad;
}
编辑广告组件
onFormSubmitEdit() {
this.activeModal.close();
this.submitted = true;
if (this.adForm.invalid) {
return;
}
const ad = this.adForm.value;
this.authService.getCurrentUser().subscribe((result) => {
if (result) {
ad.idowner = result.idUser;
this.adService.updateAd(ad).subscribe(
(res) => {
},
(err) => {
console.log(err);
alert(err.error);
}
);
}
});
}
如果您想重新加载页面,请在提交末尾添加此内容:window.location.reload();
也许这会有所帮助
我已经设法解决了问题:
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['Your actualComponent']);
});
我有一个父组件 AdsbyuserComponent,我需要使用 ag-grid 编辑或添加一行。 我已经设法将信息发送到服务器,但是在关闭弹出窗体时,我无法刷新 table。 这是我的代码
AdsbyuserComponent
update(ad :Ad) {
let ngbModalOptions: NgbModalOptions = {
backdrop : 'static',
keyboard : false ,
};
const modalRef = this.modalService.open(EditAdComponent,ngbModalOptions);
modalRef.componentInstance.ad = ad;
}
编辑广告组件
onFormSubmitEdit() {
this.activeModal.close();
this.submitted = true;
if (this.adForm.invalid) {
return;
}
const ad = this.adForm.value;
this.authService.getCurrentUser().subscribe((result) => {
if (result) {
ad.idowner = result.idUser;
this.adService.updateAd(ad).subscribe(
(res) => {
},
(err) => {
console.log(err);
alert(err.error);
}
);
}
});
}
如果您想重新加载页面,请在提交末尾添加此内容:window.location.reload();
也许这会有所帮助
我已经设法解决了问题:
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
this.router.navigate(['Your actualComponent']);
});