angular - 单击以编辑按钮并单击后保存 - 我该怎么做?
问题描述
如何连接这些按钮,以便在按下 Edit 并执行其功能后变成带有其功能的注册?
我的按钮:
<button mat-button color="primary" class="btn-block" type="button" (click)="enableEdit()">Edit</button>
<button mat-button color="primary" class="btn-block" type="submit" [disabled]="!registerForm.valid">Register</button>
我的 ts 编辑功能:
enableEdit(){
this.disableForm = !this.disableForm;
if(!this.disableForm) this.registerForm.disable();
else this.registerForm.enable();
}
提前致谢!
解决方案
您可以简单地onSubmit
通过enableEdit
以下方式调用:
enableEdit() {
this.disableForm = !this.disableForm;
if (this.disableForm) {
this.registerForm.disable();
} else {
this.registerForm.enable();
this.onSubmit(); <-- call onSubmit
}
}
为了安全起见并避免提交无效表格,您可以onSubmit
先检查一下:
onSubmit() {
if (!this.registerForm.valid) {
console.log('Invalid form');
return;
}
推荐阅读
- ruby-on-rails - 如何确定我的应用在达到 Twitter API 的速率限制之前还能发出多少请求?
- heroku - 试图在 Heroku 上服务 ML (pytorch) 模型,slug 太大
- .net - 使用异步正确调用匿名方法
- c# - 为什么我不能从我的应用程序中的另一个类调用这个公共方法?
- android - 错误膨胀类片段...以前的都没有帮助..不知道错误
- swift - Swift - 如何使用 FireStore 身份验证
- oop - 单一责任原则有什么用?
- java - 改造通用基本方法的请求
- dart - 如何在 Flutter App 中管理选项卡之间的状态
- c++ - 如何在不使用 new 的情况下使在其他对象中创建的对象保持活动状态?