Currently using AngularJS in conjunction with C# webapi.
I'm working on creating an input control that utilizes typeahead to display returned data as the user types.
Below is how I have set up the typeahead:
HTML:
<input type="text" name="uName" ng-model="uName" autocomplete="off" required class="form-control input-medium" placeholder="Enter user name..."
typeahead="uName for uName in getUserNames($viewValue)" />
Controller:
$scope.getUserNames = function (search) {
myService.getUserNamesFromApi(search).then(function (response) {
$scope.foundNames = [];
if (response.length > 0) {
for (var i = 0; i < response.length; i++) {
$scope.foundNames.push({ 'uName': response[i].uName });
}
return $scope.foundNames;
}
});
};
The data returned from the API is structured as an array, for example:
0: {fName: "Adam", lName: "Smith", uName: "asmith123"},
1: {fName: "John", lName: "Bambi", uName: "jbambi456"}
And so forth...
My goal is to extract the uName part and add it to my array before returning it. However, currently the code displays nothing without any errors. What could I be overlooking?