How to bind 2 models to one input field in Angular?

You cannot, but there are some workarounds.

1. Use ngChange to update the other model

<input type="text" 
       ng-model="sn_number" 
       ng-change="id=sn_number"/> 

2. You could watch a model, and when in changes, update another

$scope.$watch('sn_number', function(v){
  $scope.id = v;
});

You would need to watch also for changes in id if you want to keep them in sync.

Example here

Leave a Comment