javascript - AngularJS $http.get returns undefined and $http() is not a function -
i'm building app dynamically load , display data database in angularjs, when try access api (using either $http() or $http.get()), receive errrors. $http.get() error: typeerror: undefined not function
, $http() error: typeerror: object not function
this specific error occurs in code dynamically load navigation tabs.
the code both in coffeescript:
p4pcontrollers.controller 'navctrl', [ '$routeparams' '$scope' '$http' ($http,$scope,$routeparams) -> $http( method:'get' url:'http://p4p-api.snyx.nl/tables' ).success (data) -> $scope.tabs = data return return $http.get('http://p4p-api.snyx.nl/tables').success (data) -> $scope.tabs = data return return ]
does see i'm doing wrong here?
when using array notation injecting dependencies, order of arguments important:
in code:
['$routeparams', '$scope', '$http', function ($http, $scope, $routeparams) { // $http argument ==> $routeparams // $scope argument ==> $scope (by coincidence) // $routeparams argument ==> $http }
so, basically, doing $routeparams.get()
, $routeparams
has no method get()
(nor function itself).
Comments
Post a Comment