我的目的是在 AngularJS 中使用 REST 网络服务,我现在正在做一些试验。下面的代码不起作用并抛出以下异常。 你能帮我找出问题所在吗?
提前致谢。
function getUsersFromLocal($scope,$http)
{
$http.get('http://localhost:8080/people').
success(function(data) {
$scope.data = data;
});
return data;
}
错误是:TypeError: Cannot read property 'get' of undefined 在 getUsersFromLocal。
该服务是可访问的,我通过一些 REST 客户端对其进行了测试。
最佳答案
像这样尝试,这是我在 w3school 上找到的。
var app = angular.module('myApp4', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {
$scope.data= response.records;
});
});
关于javascript - Angularjs $http.get 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875703/