Hi all I want to fetch the input value from Buyer_name
into Copied Buyer_name
input field.i tried many ways but unable to find the solution if anyone knows the solution please help me....my plunk
controller:-
$('#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">
My Data:-
$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"
},
http://plnkr.co/edit/VIZkyM08IKuSChL5vvOL?p=preview
HTML - remains as is
JS - changed jQuery to angular functionality.
The way your ng-model is set at the moment assigns the $scope.state.quantity as the selected state rather than the quantity value from that state.
$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;
}
});