I'm serving value as fast as I can when user submitted current value. In this case after submitting current value I'm resetting the form and serving new value to user. It working as async call form.reset execution completes after serving new value so at the end my user get null/empty value.
Is there any alternative ways to achieve this or any chances of making it sync
code:
.ts
@ViewChild('f') form
ngOnInit() {
this.initialCall();
}
initialCall() {
this.name = 'Angular 5';
}
onSubmit(){
this.form.reset(); //reset form
this.initialCall(); //serve next value
}
.html
<form #f="ngForm" (ngSubmit)="onSubmit(f.value)">
<label>Name</label>
<input type="text" [(ngModel)]="name" name="initail">
<button type="submit">Done</button>
</form>
What I'm expecting is after click on Done button I need to show 'Angular 5' in text field but it showing empty.
And do any one can explain why change detection not happening here ?
onSubmityou get the name.