Is there anyway that I can bind two model values to one input field?
Suppose I have input field which I want to be the value of two variables in the scope something like:
<input type="text" model="sn_number; id" >
[value]=“username” - Binds the expression username to the input element's value property. (input)=“expression” - Is a declarative way of binding an expression to the input element's input event (yes there's such event) username = $event. target.
The solution is ng-bind-template, it can bind more than one {{}} expression, so it can show more than a single value that was declared in the Script function.
The answer is: (ngModel) causes a 1-way data-binding, whereas [(ngModel)] ensures a two-way data binding.
You cannot, but there are some workarounds.
<input type="text" ng-model="sn_number" ng-change="id=sn_number"/>
$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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With