I assume it should be a common pattern how people deal with it, but I am surprised why I can't find anything on the internet.
Lets say I have array of objects and I want to display these objects for customer in typeahead window. When customer select something I want to remember customer choice and process further.
Problem: All items displayed in customer readable format - item.name (London, Lisbon, Manchester) When customer select something, my ng-model fromSelected equals just to city string name, which means nothing for me, because I still need id for further processing.
Could you please suggest how I can make fromSelected be equal to object rather than string but at the same time provide friendly output to user?
var app = angular.module("fly");
app.controller('PlaceController', function($scope) {
$scope.fromSelected ='';
$scope.getPlace = function() {
var items = []
items.push({
'id': 1,
'name': London
});
items.push({
'id': 2,
'name': Lisbon
});
return items;
};
});
HTML:
<input type="text" ng-model="fromSelected" placeholder="Country, city or airport" typeahead="place.name for place in getPlace()" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
fromSelectedwill haveplaceselected object..you could simply dofromSelected.id