I have a simple form that looks like this
and need to
Below solution is working in my case, please try this simple solution. I am not sure, if it will be working into all the conditions:
<form #documentEditForm="ngForm" id="ngForm" (ngSubmit)="save(documentEditForm.valid)">
...Your Input Elements...
</form>
The button should be declared outside the form like this:
<button form="ngForm">Submit</button>
The validation of the form should check into save() by following conditions
save(isValid:boolean){
if(isValid) {
...Your code to save details...
}
}
Hope this simple solution will help you.
The correct way of doing is actually
<form (ngSubmit)="save()" id="ngForm" #documentEditForm="ngForm">
...
</form>
<button class="btn-save button primary" form="ngForm" [disabled]="!documentEditForm.form.valid">
SAVE
</button>
The form needs to have an ID id="example-form"
and the submit button a matching ID in the form="example-form"