Most of the time you’ll use your Angular filter inside your view, but sometimes it’s useful to use it from inside your controller. To do this, you have to inject the ‘filterFilter’ service:
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
'use strict'; | |
(function (app) { | |
var invoicesController = function ($scope, filterFilter, invoicesService) { | |
invoicesService.getInvoices().then(function (response) { | |
$scope.invoices = response.data; | |
}).catch(function (data) { | |
$scope.invoices = null; | |
})['finally'](function () { | |
}); | |
var applyFilters = function (search, invoices) { | |
$scope.filteredInvoices = filterFilter(invoices, search);; | |
}; | |
}; | |
app.controller('invoicesController', ['$scope','filterFilter','invoicesService', invoicesController]); | |
}(angular.module('invoicesApp'))); |