service.js
angular.module('users.background.image', [])
.factory('changebgimage', ['$http', '$q', '$rootScope', function($http, $q, $rootScope){
'use strict';
var service = {
changeRandomImage : changeRandomImage
};
function changeRandomImage(){
/*var random = $scope.data[Math.floor(Math.random() * $scope.data.length)];
$scope.imageSource = random;*/
var url = 'webService/imageUrl.htm';
var deferred = $q.defer();
$http.get(url)
.success(function(data){
deferred.resolve(data.data);
})
.error(function(error){
deferred.reject(error.message);
});
return deferred.promise;
}
return service;
}]);
aa.js
angular.module('users.da', ['users.background.image'])
.controller('da', ['user', '$scope', 'changebgimage', function (user, $scope, changebgimage) {
'use strict';
changebgimage.changeRandomImage()
.success(function (data) {
console.log(data);
}).error(function(error){
console.log(error);
});
}]);
imageUrl.htm
[{
"id": 1,
"path": "images/bg/1.jpg"
},
{
"id": 2,
"path": "images/bg/2.jpg"
},
{
"id": 3,
"path": "images/bg/3.jpg"
},
{
"id": 4,
"path": "images/bg/4.jpg"
},
{
"id": 5,
"path": "images/bg/5.jpg"
},
{
"id": 6,
"path": "images/bg/6.jpg"
}]
I am trying to get the value from service in angular but getting error changebgimage.changeRandomImage(...).success is not a function I can't understand why i am getting this error. Can anyone please take a look and assist me what is doing wrong on it promise is passing correctly.