我使用angular $ http来调用webservice,但我无法从服务中获取任何数据,状态始终为0,
var httpurl = "http://127.0.0.1:3000?orderCode=700501898";
var myApp = angular.module('piechart', []);
myApp.factory('MyService', ['$http', function ($http) {
return new function () {
this.GetName = function () {
return $http({
url: httpurl,
method:'GET'
})
};
};
}]);
angular.injector(['ng', 'piechart']).invoke(function (MyService) {
MyService.GetName();
});
答案 0 :(得分:1)
为什么要将$http
服务封装两次?
var httpurl = "http://127.0.0.1:3000?orderCode=700501898";
var myApp = angular.module('piechart', []);
myApp.factory('MyService', ['$http', function ($http) {
return {
GetName:function () {
return $http({
url: httpurl,
method:'GET'
})
}
};
}]);
angular.injector(['ng', 'piechart']).invoke(function (MyService) {
MyService.GetName();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>