0

I have a form and this is the code for on of the input fields:

 <input type="text" name="user[job]" ng-model="updateAccountForm.user.job" ng-init="updateAccountForm.user.job = '{{user.job}}'" value="{{user.job}}" />

The value is showing correctly. The problem is the following: If I edit the field the value is sent correctly in the PUT request. If I do not edit the form field then the value that is sent is literally {{user.job}}

What could be wrong with my code?

1 Answer 1

1

Because you are doing it wrong, you have to do something like this:

 <input type="text" name="user[job]" ng-model="updateAccountForm.user.job" ng-init="updateAccountForm.user.job=user.job" />

I suggest you to avoid this initialization, why you don't put your logic into the controller?

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! That works, although it doesn't set the initial value in the form field.
Not as intended :p This is an edit form and it's supposed to show the current values of the user(job, etc) in the input fields. That is working correctly. The problem is that when I do not submit the form fields the values that is sent to the server is {{user.job}}, literally.
Sorry, I forgot to explain you that value="{{user.job}}" can be omitted. You are using ng-model to set the default property value
It's solved. The problem is that user.job is only set when an async function ends running. I had to call $watch and update $scope.updateAccountForm.user.job there. Anyway, I'll accept your answer because you pointed me in the right direction :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.