javascript - 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 ....
??
Do I need to use any JS functions on controller side for this ?
解决方案
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;
}
推荐阅读
- php - Laravel - 即使我没有创建该列,它也在寻找“deleted_at”列
- typescript - 为什么 TypeScript 类型保护“in”不将类型缩小到 keyof 类型?
- python - 使用 pygame-change 播放音频时,python 不能中断 while 循环
- jquery - 获取jQueryUI的datepicker中范围之间的天数
- android - ConstraintLayout 与 RelativeLayout 性能 2020
- c# - 防止调试器在特定代码块/方法的持续时间内中断
- ios - gradle 的 Kotlin/native cinterop 构建问题
- c++ - 根据文件中的条目创建对象
- php - 无法获取 woocommerce 产品的自定义字段
- java - 强制java程序使用GTK2