2016-06-30 27 views
0

我無法將一個字段的值複製到下一個字段中。我在po num中使用了typeahead。如果我同時選擇po num的值,則自動填充quantity值,並且需要從quantity複製copied quantity的值。
這是鏈接... my plunk ...請幫我解決這個問題。
例如: - 如果我從下拉列表中選擇po num作爲1356,則自動提取quantity值爲100。我希望copied quantity的值與100相同。AngularJS - 我怎樣才能從一個輸入字段獲取值到另一個字段使用angular.copy?

我已添加我在下面使用的代碼。請確認一下,讓我知道我犯了什麼錯誤。我知道它也可能是一個非常小的東西,請幫忙。在此先感謝

my plunk

控制器: -

$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": "" 
    }, 
    ] 

回答

2

ng-repeat爲創建的子項創建一個獨立的範圍。

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

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

此外,在您的手錶表達式中,您錯誤地輸入了states(您檢查了state)。

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

+0

這是一個表單數據的一部分,如果我使用$父,數據沒有得到保存..我用MEANJS –

相關問題