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
Post a Comment