如何从一个输入获取值到另一个输入?

How to fetch value from one input into another?

大家好我想从Buyer_name获取输入值到Copied Buyer_name输入field.i尝试了很多方法但找不到解决方案如果有人知道解决方案请帮助我。 ...my plunk

控制器:-

$('#supname').change(function() {
$('#supnamecopy').val($(this).val());

});

Html:-

 <label for="quantity">Quantity</label>
      <input type="text" ng-model="state.quantity" id="quantity" typeahead="state as state.quantity for state in states | filter: $viewValue">

 <label for="quantity">Buyer_name</label>
      <input type="text" id="supname" ng-model="state.quantity" typeahead="state.buyer_name  for state in states | filter: $viewValue">

 <label for="quantitycopy">Copied Buyer_name</label>
      <input type="text" name="supnamecopy" id="supnamecopy" ng-model="copied">

我的数据:-

    $scope.states = [{
"_id": "5744009c2f0f2bef0ca707ef",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"description_count": "check",
"description_quality": "new",
"__v": 1,
"created": "2016-05-24T07:19:56.471Z",
"cone": "pending",
"status": "pending",
"currency": "Rs",
"unit": "KG",
"price": [
"500",
"400"
],
"actual_devlivery_date": "2016-05-2",
"ex_india_date": "2016-05-24",
"quantity_unit": "KG",
"quantity": "34",
"enquiry_received_date": "2016-05-24",
"supplier_name": "Mani selvam",
"buyer_name": "Rohit"
},

试试这个。这也将为您提供副本的实时预览

<label for="quantity">Buyer_name</label>
      <input type="text" id="supname" ng-model="state.quantity" typeahead="state.buyer_name  for state in states | filter: $viewValue">

 <label for="quantitycopy">{{state.quantity}}</label>
      <input type="text" name="supnamecopy" id="supnamecopy" ng-model="copied">

http://plnkr.co/edit/VIZkyM08IKuSChL5vvOL?p=preview

HTML - 保持原样

JS - 将 jQuery 功能更改为 angular。

目前您的 ng-model 设置方式将 $scope.state.quantity 指定为选定状态,而不是该状态的数量值。

$scope.$watch('state.quantity', function() {
    if($scope.state && $scope.state.quantity && $scope.state.quantity.buyer_name) {
        $scope.copied = angular.copy($scope.state.quantity.buyer_name);
    } else {
        $scope.copied = null;
    }
});