I am practicing template-driven forms in Angular. Below is the example of this simple form.
import { NgForm } from "@angular/forms";
onSubmit(form: NgForm): void {
console.log(form.value);
}
<form #myForm="ngForm" (ngSubmit)="onSubmit(myForm)">
Username:
<input type="text" name="user_name" ngModel/>
Password:
<input type="password" name="password" ngModel/>
<button type="submit">Submit</button>
</form>
The default way of logging to the console is like the following,
password: "123456" user_name: "shah"
But I want the keys should be shown according to the order in the form, like this,
user_name: "shah" password: "123456"
Is there any way to do this?