我正在寻找一种在对用户透明的 CRUD 操作之后重新加载页面的方法。
实际上在创建或删除之后,我必须重新加载页面以显示我的操作。
我使用 api 来制作这个,当我将它与 json 文件一起使用时,它工作正常。
谢谢
删除示例:
dataSource = new MatTableDataSource();
displayedColumns = ['first_name', 'middle_name', 'last_name', 'mail', 'role', 'action'];
action: any;
selectedUser: User;
@Input() user: User;
data: any;
@ViewChild(MatSort, {static: true}) sort: MatSort;
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
constructor(private formBuilder: FormBuilder, private userService: UserService, public dialog: MatDialog) {
}
ngOnInit() {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
this.userService.getUsers()
.subscribe(
(response) => {
this.dataSource.data = response;
},
(error) => {
console.log('error ' + error);
}
);
}
onDelete(selectedUser){
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
this.userService.delete(selectedUser.id).subscribe(res => {
this.dataSource.data.splice(selectedUser.id, 1);
});
Swal.fire(
'Deleted!',
'User has been deleted.',
'success'
)
}
})
}
慕码人2483693
慕尼黑的夜晚无繁华
潇潇雨雨
求助重新加载页面问题(详细见补充)
加载新页面
有没有办法在javascript中成功检测页面重新加载
pjax加载页面刷新之后的问题
相关分类