AngularJS $ http.get returns undefined, and $ http () is not a function

I am creating an application to dynamically load and display data from a database in AngularJS, but when I try to access my API (using either $ http () or $ http.get ()), I get errors. Error $ http.get (): TypeError: undefined is not a function , error $ http (): TypeError: object is not a function

This error occurs in the code for dynamically loading navigation tabs.

Code for 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 anyone see what I'm doing wrong here?

+7
javascript angularjs coffeescript
source share
1 answer

When using array notation for dependency injection, it is important to have the order of the arguments:

In your code:

 ['$routeParams', '$scope', '$http', function ($http, $scope, $routeParams) { // $http argument ==> $routeParams // $scope argument ==> $scope (by coincidence) // $routeParams argument ==> $http } 

So basically you do $routeParams.get() , but $routeParams does not have a get() method (and is not a function itself).

+9
source

All Articles