【发布时间】:2021-08-17 08:07:15
【问题描述】:
在使用弹出窗口向表格添加新文章后,我尝试刷新我的表格,但我的代码没有做我需要的事情,它可以正常工作,但没有刷新我的表格 这是我的 createModal 函数
createModal(){
const modalRef = this.modalService.open(SelectNewArticleModalComponent,{ size: 'lg' });
//modalRef.componentInstance.id = undefined;
modalRef.result.then(() =>{
this.tournee = this.creationTourneeService.getTournee();
this.changeDetectorRef.detectChanges();
}
);
}
在模式中,我尝试将我的数据添加到服务中名为“tournee”的本地属性
这是我的模态组件.ts
export class SelectNewArticleModalComponent implements
OnInit,
OnDestroy {
private subscriptions: Subscription[] = [];
formGroup: FormGroup;
codes: string[];
detail: Observable<Article[]>
articles: Article[] = [];
constructor(public modal: NgbActiveModal,
public articleService: ArticleService,
private creationTourneeService: CreationTourneeService,
private fb: FormBuilder,
) { }
ngOnInit(): void {
this.articleService.fetchNonSelectedArticle(this.creationTourneeService.getTournee().code);
this.loadForm();
const sb = this.articleService.isLoading$.subscribe(res => this.isLoading = res);
this.subscriptions.push(sb);
}
ngOnDestroy() {
this.subscriptions.forEach((sb) => sb.unsubscribe());
}
dismiss() {
this.modal.dismiss();
}
loadForm() {
this.formGroup = this.fb.group({
articles: [this.articles],
});
}
SaveArticles() {
const tournee = this.creationTourneeService.getTournee();
for(let code of this.grouping.getSelectedRows()){
this.articleService.getItemByCode(code).subscribe(res=>{
const detailTournee: DetailTournee = new DetailTournee();
detailTournee.article = res;
detailTournee.articleCode = res.code;
tournee.detailTournees.push(detailTournee);
});
}
this.creationTourneeService.setTournee(tournee);
this.modal.close();
}
}
【问题讨论】:
标签: angular typescript datatable modal-dialog refresh