So, I am stuck here most probably because of my limited understanding of promise Object.
my function that fetch data from factory is
$scope.getLogoFromService = function() {
console.log('getLogoFromService called');
var promise =
logoService.getLogo();
promise.then(
function(payload) {
console.log(payload.data.home_header.logo.file_path);
$scope.logoPath = payload.data.home_header.logo.file_path;
},
function(errorPayload) {
$log.error('failure loading logo', errorPayload);
});
};
the Variable is accessible on the view if I do {{logoPath}}, and when I console.log inside the function, but not accessible in another function.
$scope.UpdateLogo = function ()
{
console.log('UpdateLogo called');
console.log($scope.logoPath);
}
returns undefined.
my service code, just in case you need to view
App.factory('logoService', function($http) {
return {
getLogo: function() {
return $http.get('cms/general');
}
}
});
UpdateLogoget called? You're likely calling it before the promise has resolved.getLogoFromServiceandUpdateLogoat the same time then that is your problem;$scope.logoPathis infact undefined whenUpdateLogois called.