Reputation: 514
I am using Angular HTTP get request to get data from .net web api web service, Both the websites (angular and web services) are deployed on same web server. Here is the service code to get json list of all websites from service:
this.getAllWebsites = function (callback) {
return $http.get($rootScope.url + 'GetAllWebsites').success(function (data) {
callback(data)
});
}
this is what I am doing in controller:
//function triggered at the intialization of controller
$scope.init = function () {
$scope.model = [];
websiteService.getAllWebsites(function (data) {
$scope.model = data;
websiteService.paginate($scope);
});
};
My url is correct, the problem is that when I debug my JavaScript code, service returns data else it does not return any data. I know that problem is in promise that is not being returned, Please suggest any workaround.
Upvotes: 0
Views: 55
Reputation: 503
this.getAllWebsites = function (callback) {
return $http.get($rootScope.url + 'GetAllWebsites').then(function (response) {
return response.data
});
}
In controller
//function triggered at the intialization of controller
$scope.init = function () {
$scope.model = [];
websiteService.getAllWebsites().then(function (data) {
$scope.model = data;
websiteService.paginate($scope);
});
};
Upvotes: 1