This answer is close to what I'm trying to do. I'm also branching from its original Plunker to this new Plunker
The original plunker has a text box that auto-completes where the auto-complete options are hard coded in a list.
I've added a service to the new plunker that gets some information about stackoverflow badges in JSON. How can I have the auto-complete use the JSON data to provide a list of badge names for the auto-complete options?
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<script data-require="angular.js@1.3.9" data-semver="1.3.9" src="https://code.angularjs.org/1.3.9/angular.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script>
var app=angular.module('app',[]);
app.factory('badges', ['$http', function($http) {
return $http.get('https://api.stackexchange.com/2.2/badges?page=1&order=desc&sort=rank&site=stackoverflow')
.success(function(data) {
return data;
})
.error(function(err) {
return err;
});
}]);
app.controller('ctrl', ['badges', function($scope, badges){
badge_names = how do I make a list of badge names from badges.success?;
$scope.availableTags = badge_names;
});
$scope.complete=function(){
$( "#tags" ).autocomplete({
source: $scope.availableTags
});
}
});
</script>
</head>
<body ng-app="app" ng-controller="ctrl">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" ng-keyup="complete()"/>
</div>
</body>
</html>