angular - 无法获取空的用户表单
问题描述
我的代码仅适用于使用编辑按钮加载数据,我可以更新数据!!!但是当我单击菜单中的 AddNew 车辆选项以添加新数据时,我得到的表单中的加载值为上次编辑。没有得到空表单来添加新数据。
如果我没有点击编辑按钮,那么菜单中的 AddNew 车辆选项来添加新数据,我会得到 Empty 表单来添加新数据。
我该如何解决这个问题。
解决方案
问题是您正在重定向到同一条路线。因此角度防止它。
只需将这么多代码放入
user-form.components.ts
要导航到的组件 ( ) 的构造函数中。
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
this.router.events.subscribe((evt) => {
this.router.navigated = false;
});
另外,为菜单点击添加一个回调函数:
items: [
{
label: 'Add New Vehicle', icon: 'fa fa-refresh',
command: () => {
let user = new User();
this._userService.setter(user);
this.router.navigate(['/op']);
}
},
{ label: 'Show All', icon: 'fa fa-repeat', url: '#' }
]
工作代码链接: https ://stackblitz.com/edit/angular-xjhvtj?file=src%2Fapp%2Fapp.component.ts 工作示例链接: https ://angular-xjhvtj.stackblitz.io
推荐阅读
- java - Eclipse:触发完全重建
- javascript - 如何通过 id 获取 span 元素?
- javascript - 如何使用插入到 Javascript 中的 SQLite 列中的值?
- java - JAVA 根据属性值删除 XML 节点
- python - 多跳 SSH 中的 Python Paramiko listdir
- shell - ksh:获取数组的最后一个元素 - 找不到命令
- ios - 为 CollectionView [Swift] 的单独 Cell 设置圆形标签
- ios - MobileVLCKit 如何播放带有一些空帧的视频流?
- laravel - 从用户表中检索团队中每个成员的用户名
- java - 有没有更简洁的方法可以在 Java 中编写多个 if 语句