I have two buttons on my Angular2 Form Component. The button are doing their own functionalities.
- Button Submit : Which is submit all the values to the API.
- Button Add. : Which is push an object to an array.
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);
}
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>
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