I know that [(ngModel)] is for 2-way binding.
I have an input field. It should display a value from the db, and allow user to change it and save back into the db.
For this, I believe I should use [(ngModel)] so that the field value can be set from the variable (retrieved from db) in the ts file. Can this same be achieve in any other way just using ngModel like below?
<ion-item>
<ion-label floating>First Name</ion-label>
<ion-input type="text" ngModel name="firstName" required></ion-input>
</ion-item>
It's called Template Driven Approach
Inserting ngModel
ionic will know this has an action to handle through Javascript representation. This is known as registering controlls
You could achieve the same as
<form #f="ngForm" (ngSubmit) = "onAddItem(f)">
:
#f
creates a local reference and has access to HTML skeleton of the form. By adding "ngForm" then #f will have access to Javascript representation of the form created by Angular. (ngSubmit)
listens to the submit of the form and pass the form to the onAddItem method when submit event is triggered.