[英]Angular $http get
我想在angularJS中进行ajax调用,正在加载JSON,但未填充数据。
demoApp.controller('MainController', function($scope, GetData) {
$scope.data = null;
GetData.getDoctors(function(dataResponse) {
$scope.data = dataResponse;
});
});
demoApp.factory('GetData', function($http) {
var doctors = [];
this.getDoctors = function(callBack) {
$http({
method: 'GET',
url: 'json/location.json'
}).
success(function(data) {
callBack(data);
}).
error(function(data) {
alert("Error");
});
}
});
甚至Json文件也没有加载..代码中的错误是什么?
角工厂应该返回一些东西。
尝试
demoApp.factory('GetData', function($http) {
var methods = {};
methods.getDoctors = function(callBack) {
$http({
method: 'GET',
url: 'json/location.json'
}).
success(function(data) {
callBack(data);
}).
error(function(data) {
alert("Error");
});
};
return methods;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.