Angularjs conditional binding -


i have used angular's ng-model quite time demonstrates 2 way data binding. want accomplish bind input field model if there changes.

if have

<input value="hello world"> 

i want value propagated model variable if there changes made value.

answer depend on event want use update model.

assuming wanting "edit form " don't want master model update live can make copy of model , extend master on "save"

starting data:

$scope.item ={age: 25, name: 'foo bar'}; $scope.edititem = angular.copy($scope.item); 

html

<input ng-model="edititem.age"> <button ng-click="updateitem()">update</button> 

update function:

$scope.updateitem = function (){   $http.put(url, $scope.edititem).success(function(resp){      // merge data      angular.extend( $scope.item, $scope.edititem);   }); } 

you similar using ng-change


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -