Leong Sze Kim Leong Sze Kim - 3 months ago 7
AngularJS Question

Angular.JS service not working

I stuck on this for quite some time. My service didn't work as in it didn't get data from my expected. But it working fine if I put the

$http
request in my controller.

(function(){

function controlProvider($http) {
this.getStatus = function (callback){
$http.get("http://localhost:8080/getStatus")
.success(function (data) {
callback(data);
});
};

}
controlApp.service('controlProvider', controlProvider);


function controlController ($scope,controlProvider){
controlProvider.getStatus = (function (product) {

$scope.product = product;
});
}
controlApp.controller("controlController", controlController);

})();


Any help advise will be greatly appreciated. Thank you.

Answer
//maybe like this ?
controlProvider.getStatus(function(product) {
    $scope.product = product; 
})
Comments