(function () { 'use strict'; angular.module("app").controller("SearchCtrl", Ctrl); Ctrl.$inject = ['$http', 'modalService', 'contactsService'] function Ctrl($http, modalService, contactsService) { var vm = this; vm.contacts = []; vm.searchString = ""; vm.deleteContact = deleteContact; vm.deleteSelected = deleteSelected; vm.nameCodeFilter = nameCodeFilter; getContacts(); function getContacts(){ contactsService.getContacts() .then(function(contacts) { vm.contacts = contacts }) } function deleteContact(id) { modalService.confirm().then(function(resp) { contactsService.deleteContact(id).then(function() { console.log("Deleted contact "+id) getContacts(); }) }) }; function deleteSelected() { return; }; function matchSearchString(string) { return void 0 !== string && string.toLowerCase().indexOf(vm.searchString.toLowerCase()) >= 0 } function nameCodeFilter(contact) { return 0 === vm.searchString.length || (matchSearchString(contact.name) || matchSearchString(contact.phone)); }; }; })();