Skip to content

Commit d7bf5c1

Browse files
matiboypkozlowski-opensource
authored andcommitted
docs(typeahead): add async version of the demo
1 parent e76512f commit d7bf5c1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/typeahead/docs/demo.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<div class='container-fluid' ng-controller="TypeaheadCtrl">
2+
3+
<h4>Static arrays</h4>
24
<pre>Model: {{selected| json}}</pre>
35
<input type="text" ng-model="selected" typeahead="state for state in states | filter:$viewValue | limitTo:8">
4-
</div>
6+
7+
<h4>Asynchronous results</h4>
8+
<pre>Asynchronous values model: {{asyncSelected| json}}</pre>
9+
<input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue) | filter:$viewValue" typeahead-loading="loadingLocations">
10+
<i ng-show="loadingLocations" class="icon-refresh"></i>
11+
</div>

src/typeahead/docs/demo.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
function TypeaheadCtrl($scope) {
1+
function TypeaheadCtrl($scope, $http) {
22

33
$scope.selected = undefined;
44
$scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
5-
}
5+
// Any function returning a promise object can be used to load values asynchronously
6+
$scope.getLocation = function(val) {
7+
return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {
8+
params: {
9+
address: val,
10+
sensor: false
11+
}
12+
}).then(function(res){
13+
var addresses = [];
14+
angular.forEach(res.data.results, function(item){
15+
addresses.push(item.formatted_address);
16+
});
17+
return addresses;
18+
});
19+
};
20+
}

0 commit comments

Comments
 (0)