angular - 在同一个按钮上保存和更新?
问题描述
如何从同一个按钮调用保存和提交?
<button type="submit" class="btn btn-sm btn-brand"
[disabled]="!frmAgrTemp.valid" (click)="SubmitInfo()">
Save
</button>
<button type="submit" class="btn btn-sm btn-brand"
[disabled]="!frmAgrTemp.valid" (click)="UpdateInfo()">
Update
</button>
解决方案
一般来说,您可以有一个变量来指示何时是新的注册,例如
newReg:boolean=true
//at very first, e.g. in ngOnInit if params get a parameter you can make
this.newReg=false
那么你有两个选择:
1.-两个带有 *ngIf 的按钮来显示一个或另一个
<button type="submit" *ngIf="newReg" ...>Save</button>
<button type="submit" *ngIf="!newReg" ...>Update</button>
2.-更改标题的独特按钮和保存或更新注册表的独特功能
<button type="submit" (click)="Submit()" >{{newReg?'Save':'Update'}}</button>
Submit()
{
if (this.newReg){
..save the reg..
}
else{
..update the reg..
}
}
推荐阅读
- excel - 将 Excel SUMPRODUCT 与多条件 COUNTIF 相结合
- angular - Angular 错误页面组件使用带有 id 的路由而没有重定向
- animation - 使用按钮交互重放 ThreeJs 动画
- android - Android MVVM 对话框视图模型
- elasticsearch - 是否可以为弹性搜索索引中的属性设置默认数据类型
- flutter - 无法使用冻结包生成 classname.g.dart 类
- jsf - inputNumber 不起作用,即允许使用字母
- powershell-2.0 - 使用 PowerShell 搜索驱动器上的所有文件夹和子文件夹
- javascript - 在材料 ui 卡中将页脚与底部对齐(内部示例)
- react-native - 如何实现这个动画平面列表