简体   繁体   English

AngularJs-如何使用angular.copy将值从一个输入字段取到另一个字段?

[英]AngularJs - How can i fetch the value from one input field into another field using angular.copy?

I am not able to copy a value from one field into the next. 我无法将值从一个字段复制到下一个字段。 I used typeahead in po num . 我在po num使用了typeahead。 If I select po num value from typeahead simultaneously the quantity value is autofilled, and the value for copied quantity needs to be copied from the quantity . 如果同时从预输入中选择po num值,则会自动填充quantity值,并且需要从quantity copied quantity的值。
This is the link to ... my plunk ...please help me on this issue. 这是... 我的pl ...的链接,请在这个问题上帮助我。
For instance:- If I select po num as 1356 from drop-down, the quantity value is fetched automatically gives as 100 . 例如:-如果我从下拉列表中选择po num作为1356 ,则自动获取的quantity值为100 I want the copied quantity value to reflect the same as 100 . 我希望copied quantity值反映为100

I've Added the code that I've used below. 我添加了下面使用的代码。 Please do have a look and let me know where I've made the mistake. 请看看,让我知道我在哪里弄错了。 I know it could be something insanely small as well, please do help. 我知道这可能也太小了,请提供帮助。 Thanks in advance 提前致谢

my plunk 我的朋克

Controller:- 控制器:

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

Html:- HTML:

    <div ng-repeat="states in states.pocomments">
       <label for="purchase_order_details_ord_no">po num</label>
          <input type="text" ng-model="states.purchase_order_details_ord_no" id="purchase_order_details_ord_no" typeahead="type as type.purchase_order_no for type in types | filter: $viewValue">
      <label for="quantity">quantity</label>
          <input type="text" id="supname" ng-model="states.purchase_order_details_ord_no" typeahead="type.getTotalsshadeqty  for type in types | filter: $viewValue">
      <label for="quantitycopy">Copied quantity</label>
          <input type="text" name="supnamecopy" id="supnamecopy" ng-model="copied">
  </div>

My data:- 我的数据:

    $scope.types = [
{
"_id": "5768e6c8bdbc5db509f0f2b2",
"created": "2016-06-21T07:03:36.504Z",
"getTotalsshadeqty": "100",
"getTotalsprice": "1000",
"getTotalsqtyprice": "100000",
"purchase_order_no": "1356",
},
{
"_id": "5767cd78f5012d790aa41a7b",
"created": "2016-06-20T11:03:20.382Z",
"getTotalsshadeqty": "12",
"getTotalsprice": "10",
"getTotalsqtyprice": "120",
"purchase_order_no": "0987",
}];

$scope.states = {
  "_id": "575691b26a5ec735128fe635",
  "pocomments": [
  {
  "_id": "575691d56a5ec735128fe636",
  "po_value_currency": "Rs",
  "value": "124",
  "rate": "24",
  "quantity": "",
  "purchase_order_details_ord_no": ""
  },
  ]

ng-repeat creates an isolated scope for the children created. ng-repeat为创建的子代创建隔离的作用域。

You need to add a $parent to the accessor of your model-properties if you want to change properties outside of the isolated scope. 如果要更改隔离范围之外的属性,则需要在模型属性的访问器中添加$parent

Eg. 例如。 ng-model="$parent.states.purchase_order_details_ord_no"

Additionally inside your watch-expression you mistyped states (you checked for state ). 此外,在监视表达式内部,您输入了错误的states (检查了state )。

Fork that should work as expected: http://plnkr.co/edit/QAgJZToxkqvtg7pFSseO?p=preview 应该可以按预期工作的叉子: http : //plnkr.co/edit/QAgJZToxkqvtg7pFSseO?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM