I have done an autocomplete from a json file in an input tag, the json file has multiple attributes, i want a separate input carry a different attribute from the json file, eg: one one input should fetch the "driver_name" and other should fetch the "vehicle_number", the second input tag needs to be filled automatically, once we select the data from the first input tag
[
{
"id": 1,
"driver_name": "Rohit",
"driver_phone": "9176649143",
"vehicle_type": "indica",
"vehicle_number": "TN 06 AR 4556"
},
{
"id": 2,
"driver_name": "john",
"driver_phone": "9176648143",
"vehicle_type": "fiat",
"vehicle_number": "CA 06 AR 4556"
}
]
HTML
<div ng-controller="TypeaheadCtrl">
<div class="input-group m-bot15">
<input ng-model="tripsheet.vehicle_no" type="text" class="form-control input-lg" placeholder="Vehicle No" typeahead="Unidade.vehicle_number as Unidade.vehicle_number for Unidade in getUnidades($viewValue)">
</div>
<div class="input-group m-bot15">
<input ng-model="tripsheet.driver_name" type="text" class="form-control input-lg" placeholder="Vehicle No" typeahead="Unidade.driver_name as Unidade.driver_name for Unidade in getUnidades($viewValue)">
</div>
</div>
JS
function TypeaheadCtrl($scope, $http) {
$scope.Selected = undefined;
$scope.getUnidades = function($viewValue) {
return $http.get(urldr + '/all').then(function(response){
return response.data;
});
};
}