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

后端 未结 4 1976
南笙
南笙 2020-11-30 21:59

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

4条回答
  •  悲哀的现实
    2020-11-30 22:57

    You cannot, but there are some workarounds.

    1. Use ngChange to update the other model

     
    

    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

提交回复
热议问题