-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.js
34 lines (26 loc) · 909 Bytes
/
search.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function SearchController($scope, $q) {
this.modes = {};
this.options = {};
this.lastSearch = "";
this.tags = [ {text:'bacon'},{text:'ham'},{text:'eggs'},{text:'cheese'},{text:'onions'},{text:'chili'},{text:'ketchup'},{text:'catsup'},
{text:'herp'},{text:'derp'},{text:'serp'},{text:'perp'},{text:'twerp'} ];
this.loadResults = function($query) {
var deferred = $q.defer();
var results = [];
for(var i=0; i < this.tags.length; ++i) {
if (this.tags[i].text.indexOf($query) > -1){
results.push(this.tags[i]);
}
}
deferred.resolve(results);
return deferred.promise;
};
this.select = function(item) {
var deferred = $q.defer();
this.lastSearch = item.text;
deferred.resolve();
return deferred.promise;
};
}
angular.module('TypeaheadApp')
.controller('SearchController', SearchController);