Ashish Ranjan Ashish Ranjan - 3 months ago 10
AngularJS Question

How to use ng-bind for my model?

From the documentation, its clear, with ng-bind we can update our HTML, How to use the same functionality for updating my model.

<input type="text" ng-bind="controller.model.property">


I don't want to use ng-model, Don't want to reflect changes in my input box when data is fetched from the backend.

Answer

If you don't want two-way data binding, I assume that you will process all the data at once (perhaps on a button click). The way I would do it is by creating a temporary scope variable to assign using ng-model, and then assigning it to the original variable on button click.

//template
<input type="text" ng-bind="temp.property">
<button ng-click="submit()">Save</button>

//controller
$scope.model = updateViaBackend();
$scope.temp = { property: "" };

$scope.submit = function(){
  $scope.model.property = $scope.temp.property;
}