Thibault
Thibault

Reputation: 137

AngularJS $http issue

i'm pretty new to AngularJS and i have a little problem.

I receive JSON data from an api, I display all the data with ng-repeat.

Then from each different object, when I click on Id link for exemple, i would like to display in another page only the specific data for this object. I don't have any problem with the route, I go fine to the page, but when i try form exemple to display the "Name", i get this : {{name}}

Here go my two controllers :

    var toulouseVeloControllers = angular.module('toulouseVeloControllers', []);

toulouseVeloControllers.controller('toulouseVeloListCtrl', ['$scope', '$http',
  function($scope, $http) {
    $http.get('https://api.jcdecaux.com/vls/v1/stations?contract=toulouse&apiKey=************************').success(function(data) {
      $scope.bornes = data;
    });
  }]);

    toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
      function($scope, $http) {
        $http.get('https://api.jcdecaux.com/vls/v1/stations/' + data.number + '?contract=Toulouse&apiKey=*******************************').success(function(data) {

      $scope.name = data;
    });
  }]);

Does someone can help ?

Thank you a lot !

Upvotes: 0

Views: 62

Answers (1)

Rikky
Rikky

Reputation: 515

 toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
  function($scope, $http) {....

This one is the problem, you have not injected enough dependencies in to the controller. Fixing it by add the $routeParams dependency to the controller. Like this:

 toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
  function($scope, $routeParams, $http) {....

Upvotes: 2

Related Questions