Monday, 15 March 2010

javascript - $filter is not a function AngularJS -



javascript - $filter is not a function AngularJS -

app.controller('mycontroller', ['$scope', '$http', '$filter', function($scope, $http, $filter) {

the above illustration of code trying utilize $http.get , $filter within controller.

the problem when utilize so, console log throws error says $filter not function.

app.controller('mycontroller', ['$scope', '$http', '$filter', function($scope, $filter, $http) {

when swap them round throws error $http undefined

when using

app.controller('mycontroller', ['$scope', '$http', '$filter', function($scope, $filter, $http) {

variable $filter instance of $http, , $http instance of $filter. doesn't matter written in function(...) params.

what of import here, order of injectibles using, illustration

app.controller('mycontroller', ['$scope', '$http', '$filter', function(a, b, c) {

will map instances:

a -> scope b -> $http c -> $filter

from angular docs:

since angular infers controller's dependencies names of arguments controller's constructor function, if minify javascript code phonelistctrl controller, of function arguments minified well, , dependency injector not able identify services correctly.

so using array notation yout controller, making sure code work after code minified.

javascript angularjs angularjs-scope angularjs-filter angularjs-http

No comments:

Post a Comment