One challenge I am facing involves pre-populating an input field with user information, such as their email address or first name, if that data is available.
Initially, I set the value of the input field using $scope.userData. However, when I add an ng-model attribute to the input field, the value on the front-end appears blank.
For example:
Works as expected (input field displays user's email):
<input class="text-input" type="email" value="{{data.email}}">
Does not work (input field remains blank):
<input class="text-input" type="email" ng-model="formData.email" value="{{data.email}}">
I understand why this doesn't work—the formData.email is empty and the model overwrites the value. However, I need to save this information in formData to later submit a POST request to my service upon form submission.
As a newcomer to Angular, I want to avoid relying on jQuery and solve this issue through Angular itself.
So, how can I set the email field to a model for form submission while also populating the initial email data, if available?