按下(click)按钮时会调用(ngSubmit) [英] (ngSubmit) is called when press (click) button
本文介绍了按下(click)按钮时会调用(ngSubmit)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Angular2表单组件上有两个按钮.该按钮正在执行自己的功能.
I have two buttons on my Angular2 Form Component. The button are doing their own functionalities.
- 按钮Submit:将所有值提交到API.
- 按钮添加. :将对象推到数组中.
这两种方法在这里...
The two methods are here...
onSubmit() {
this.submitted = true;
this.model.service_requests = this.modelJobServices;
this.onCreateJob();
}
addJobService(modelJobService :Jobservice){
let modelJobServiceLocal = new Jobservice(modelJobService.service_id,modelJobService.service_note,modelJobService.status)
this.modelJobServices.push(modelJobServiceLocal);
}
我的Component.html结构如下
My Component.html structure is as below
<form #jobRegistrationForm="ngForm" (ngSubmit)="onSubmit()">
......
......
......
<button class="flat btn-primary form-control" id="btn_add" (click)="addJobService(modelJobService)"> ADD SERVICE </button>
....
....
....
<button (submit)="onSubmit()" [disabled]="!jobRegistrationForm.form.valid" class="flat form-control col-md-4 btn-primary">{{BUTTON_TEXT}}</button>
当我按下(click)
按钮时,表单将提交给API调用.但是我没有在(click)
按钮事件上调用onSubmit()
when I press the (click)
button the form is submitted to the API call. But I did not call the onSubmit()
on the (click)
button event
推荐答案
默认情况下,表单内的按钮变为type="submit"
.
Buttons inside a form become a type="submit"
by default.
将它们明确地设置为普通按钮:
Make them plain buttons explicitly:
<button type="button"
这篇关于按下(click)按钮时会调用(ngSubmit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文