I am trying to inject a filter into my controller and use it as such:
angular
.module('graduateCalculator', [])
.filter('slug', function() {
return function(input) {
if(input) {
return input.toLowerCase().replace(/[^a-z-]/g, '-');
}
};
}).controller('GraduateCalculatorController', ['$filter', app.graduateCalculator($filter)]);
However, I get the above error. I am obviously doing something very wrong - just not obvious enough to me.
Uncaught ReferenceError: $filter is not defined
It may have something to do with my function. It's written like so:
var app = {
graduateCalculator: function($filter) {
window.console.log( $filter('slug')('A random looking string...') );
}
};
Help appreciated!
The 2nd parameter to [module].controller
is a constructor function, not calling the constructor function...
// change this...
.controller('GraduateCalculatorController', ['$filter', app.graduateCalculator($filter)]);
// to this...
.controller('GraduateCalculatorController', ['$filter', app.graduateCalculator]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With