Created
July 27, 2016 09:23
-
-
Save adyngom/022da3b8e4c58d551bd1731831a6a673 to your computer and use it in GitHub Desktop.
Dynamic Search Filtering in Angular JS Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('va', []) | |
.filter('highlight', highlight) | |
.factory('query', query) | |
.controller('searchlist', searchList); | |
highlight.$inject = ['$sce']; | |
function highlight($sce) { | |
return function (text, phrase) { | |
if (phrase) { | |
text = text.replace(new RegExp('(' + phrase + ')', 'i'), | |
'<span class="highlighted">$1</span>'); | |
} | |
return $sce.trustAsHtml(text); | |
} | |
} | |
query.$inject = ['$http']; | |
function query($http) { | |
function getCountries () { | |
return $http({ | |
method: 'GET', | |
url: '/json/africa.json' | |
}); | |
} | |
return { | |
listAll: getCountries | |
} | |
} | |
searchList.$inject = ["query"]; | |
function searchList(query) { | |
var vm = this; | |
vm.countries = []; | |
query.listAll() | |
.success(hasList) | |
.error(noList); | |
function hasList(payload) { | |
vm.countries = payload; | |
} | |
function noList(error) { | |
console.log(error); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment