0

I have a form and this form have some values. Input values are set using json data:

<input name="name" ng-model='user.name' value="{{user.name}}">

I want to use a different ng-model:

<input name="isim" ng-model='userProfile.name' value="{{user.name}}">

This destroy values from <input />.

  • How can I use json data and different ng-model in input?
  • How do you update a form with AngularJS?
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • Please could you explain what do you mean by input values destroys? – amrender singh Mar 21 '19 at 18:56
  • 1
    what do u mean by destroys – Guru1988 Mar 21 '19 at 18:57
  • When i using json data {{user.name}} and ng-model='formData.name', input value disapear. But if i using ng-model='user.name' its working. But i want to use ng-model='formData.name' and showing json data same time. – Walter.White Mar 21 '19 at 19:03
  • You should check how two-way data binding works in angular – Guru1988 Mar 21 '19 at 19:06
  • there is something called one-time binding {{ ::vm.user }} , it will bind for the first digest cycle after that it will remove the association with the model, can u try this. – Guru1988 Mar 21 '19 at 19:31

1 Answers1

0

Avoid using an interpolated value attribute with ng-model:

<input name="name" ng-model='user.name' ̶v̶a̶l̶u̶e̶=̶"̶{̶{̶u̶s̶e̶r̶.̶n̶a̶m̶e̶}̶}̶" >

<input name="isim" ng-model='userProfile.name'  ̶v̶a̶l̶u̶e̶=̶"̶{̶{̶u̶s̶e̶r̶.̶n̶a̶m̶e̶}̶}̶" >

Instead intialize the value from the controller:

$scope.userProfile.name = $scope.user.name;

The ng-model creates a two-way binding that will fight the one-way binding of the interpolated value attribute.

For more information, see whats the difference between ng-model and ng-value

georgeawg
  • 48,608
  • 13
  • 72
  • 95