AngularJS $http 问题
AngularJS $http issue
我是 AngularJS 的新手,有点小问题。
我从 api 接收到 JSON 数据,我用 ng-repeat 显示所有数据。
然后从每个不同的对象,例如,当我单击 Id link 时,我想在另一个页面中仅显示该对象的特定数据。我对路由没有任何问题,我可以很好地进入页面,但是当我尝试以示例形式显示 "Name" 时,我得到了这个:{{name}}
这是我的两个控制器:
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;
});
}]);
有人可以帮忙吗?
非常感谢!
toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
function($scope, $http) {....
这就是问题所在,您没有向控制器中注入足够的依赖项。通过将 $routeParams 依赖项添加到控制器来修复它。像这样:
toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
function($scope, $routeParams, $http) {....
我是 AngularJS 的新手,有点小问题。
我从 api 接收到 JSON 数据,我用 ng-repeat 显示所有数据。
然后从每个不同的对象,例如,当我单击 Id link 时,我想在另一个页面中仅显示该对象的特定数据。我对路由没有任何问题,我可以很好地进入页面,但是当我尝试以示例形式显示 "Name" 时,我得到了这个:{{name}}
这是我的两个控制器:
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;
});
}]);
有人可以帮忙吗?
非常感谢!
toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
function($scope, $http) {....
这就是问题所在,您没有向控制器中注入足够的依赖项。通过将 $routeParams 依赖项添加到控制器来修复它。像这样:
toulouseVeloControllers.controller('toulouseVeloDetailCtrl', ['$scope', '$routeParams', '$http',
function($scope, $routeParams, $http) {....