簡體   English   中英

AngularJs-如何使用angular.copy將值從一個輸入字段取到另一個字段?

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

我無法將值從一個字段復制到下一個字段。 我在po num使用了typeahead。 如果同時從預輸入中選擇po num值,則會自動填充quantity值,並且需要從quantity copied quantity的值。
這是... 我的pl ...的鏈接,請在這個問題上幫助我。
例如:-如果我從下拉列表中選擇po num作為1356 ,則自動獲取的quantity值為100 我希望copied quantity值反映為100

我添加了下面使用的代碼。 請看看,讓我知道我在哪里弄錯了。 我知道這可能也太小了,請提供幫助。 提前致謝

我的朋克

控制器:

    $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:

    <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>

我的數據:

    $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為創建的子代創建隔離的作用域。

如果要更改隔離范圍之外的屬性,則需要在模型屬性的訪問器中添加$parent

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

此外,在監視表達式內部,您輸入了錯誤的states (檢查了state )。

應該可以按預期工作的叉子: http : //plnkr.co/edit/QAgJZToxkqvtg7pFSseO?p=preview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM