首页 > 解决方案 > How copy value of input text to other inputs texts

问题描述

How copy value of input text to other Input texts elements in AngularJS 1.X

But each input has have his own property in controller

I've tried so far

 <div class="paramWrap"> // copy from here
    <label for="accoubntDis">Account Discount</label>
        <input id="accoubntDis" type="text" class="form-control" ng-model="accoubntDis">
 </div>

 <pre>{{accoubntDis}}</pre> // only this displayed

    <div class="space"></div>
    <div class="paramWrap">
        <label for="365Dis">O365 Exchange Unlicensed Discount</label>
        <input id="365Dis" type="text" class="form-control" value="{{accoubntDis}}" ng-model="accoubntDis12">
    </div>

    <div class="space"></div>
    <div class="paramWrap">
        <label for="gSuiteO365">G Suite / O365 Exchange Paused/Archived</label>
        <input id="gSuiteO365" type="text" class="form-control" value={{accoubntDis}} ng-model="gSuiteO365">
    </div>

What I see actually that only the <pre>{{accoubntDis}}</pre> is displayed

why value/ng-value={{accoubntDis}}/"accoubntDis" not worked in <input .... ??

enter image description here

enter image description here

Do I need to use any JS functions on controller side for this ?

标签: javascriptangularjs

解决方案


I tried with "ng-value", its working in angular 1.5 and above. If you angular is below 1.5 you can go for below approach.

  • So better you write a function call on change of input field1, and in that function assign the value of field1 to field2. Consider the below sample example.

HTML:

<input type="text" ng-model="data" ng-change="updateField()">
<input type="text" ng-model="meta">

JS:

  $scope.data;
  $scope.meta;
  $scope.updateField= function(){
      $scope.meta=$scope.data;
  }

推荐阅读