javascript - POST请求后如何实时刷新数据?
问题描述
我有一个显示数据的表格。一切都适用于POST
&GET
请求,但只有在刷新页面时我才能看到插入后的值。
abc.service.ts
createExamCategory(options) {
return this.http.post<{ message: string }>(this.url + '/createExamCategory', options);
}
getExamCategory():Observable<any> {
return this.http.get<any>(this.url + '/getAllExamCategory');
}
abc.component.ts
onSubmit() {
if(this.formdata.invalid) {
return;
}
this.adminCategory.createExamCategory(this.formdata.value).subscribe(reponse => {
console.log(reponse.message);
});
}
ngOnInit() {
this.columnsToDisplay = ['id', 'examCategoryName', 'isActive', 'Action'];
this.adminCategory.getExamCategory().subscribe((reponse: any) => {
this.ExamCategoryData = reponse.examCategoryList;
this.dataSource = new MatTableDataSource(this.ExamCategoryData);
this.dataSource.paginator = this.paginator;
}, error => {
console.log(error);
}
);
}
这是我的代码。我需要做哪些必要的改变?
解决方案
您在这里有两个选择:
将您发送到 POST 请求的数据直接添加到表中。
POST 刷新表后获取整个数据集。
推荐阅读
- javascript - Javascript单击事件触发在C#的控制台中打印
- python-3.x - 将字典转换为 Pandas 数据框
- pari - pari gp函数编程中的指针可选参数
- javascript - ThreeJS在链接方法时将位置偏移量添加到Matrix4
- windows - 一定时间后批量关闭并重启进程
- xcode - 如何修复多个 SwiftUI 预览
- python - 如何使用 Selenium 在表单上输入登录凭据
- floating-point - 如何计算或估计特定数字的浮点舍入误差
- java - 如何阻止 AppBarConfiguration 将汉堡图标切换到后退箭头?
- graphics - 了解 Vulkan 统一布局的“设置”索引