角$ HTTP GET [英] Angular $http get
本文介绍了角$ HTTP GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在angularJS Ajax调用,JSON是加载,但数据不填充。
I want to make an ajax call in angularJS, JSON is loading but the data is not populating.
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文件没有加载..what是在code中的错误?
Even the Json file is not loading ..what is the error in the code?
推荐答案
角工厂应该返回的东西。
Angular factory should return something.
尝试
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;
});
这篇关于角$ HTTP GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文