I am trying to make a $http call from angular service and it doesn't seem to get reflected in the html
var heroSliderApp = angular.module('heroSliderApp', []);
heroSliderApp.service('heroService', function ($http) {
this.loadSlider = function () {
$http.get("some url that returns data")
.then(function (response) {
return JSON.stringify(response.data);
//return "Hello World!"; //this doesn't work
});
};
});
heroSliderApp.controller('heroSliderController', function ($scope, $http, heroService) {
$scope.sliderValue = heroService.loadSlider(); // this doesn't work
$scope.someValue= "Testing"; //this works
});
Here the .then function gets called and response.data contains value, but the value is not getting reflected in the html
return $http.get..., and you need to use the returned promise in the controller:heroService.loadSlider().then(...). Why are you stringifying the object stored in the data of the response?