Basically, I have
<form #f="ngForm" (ngSubmit)="save(f.form)" #formElement>
...
<button class="btn btn-primary" #saveButton>Save</button>
</form>
I want to be able to trigger submit()
from the component.
I've tried @viewChild('formElement')
and renderer.invokeElementMethod
to trigger click()
.
NgForm has property
ngSubmit
which is EventEmitter. So doingemit()
on this property from the component will trigger a submit.Also you need to use your
f
variable instead offormElement
becausef
is referencing tongForm
.