I have an Angular 8 app that uses routing and template driven forms.
I have a simple form in component.html:
<form (ngSubmit)="onSubmit(serviceForm)" #serviceForm="ngForm">
<input type="text" name="endpoint" ngModel>
<button class="btn btn-success" type="submit">Submit</button>
</form>
A handler in component.ts:
onSubmit(serviceForm:NgForm){
console.log(serviceForm);
this.router.navigate(['/view-service']);
}
"Endpoint" isn't available in ngForm.value when I call the navigate statement after console.log(). Here is an output from console.log:
NgForm {submitted: true, _directives: Array(1), ngSubmit: EventEmitter, form: FormGroup}
formDirective: (...)
control: (...)
path: (...)
controls: (...)
value: Object
__proto__: Object
valid: (...)
invalid: (...)
pending: (...)
disabled: (...)
enabled: (...)
errors: (...)
pristine: (...)
dirty: true
touched: true
status: (...)
untouched: (...)
statusChanges: (...)
valueChanges: (...)
submitted: true
If I don't call the navigate statement, it is available.
I don't get it, I print out to console before I navigate.
What am I doing wrong here?
Thanks!