I have a problem using global variables in angularjs I have seen this question Global variables in AngularJS and the answer worked fine but I want to return in my service something like this
bookModule.factory('UserService', function (viewModelHelper) {
function get() {
var rt;
viewModelHelper.apiPost('Language/getLanguageIsArabic', null,
function (result) {
rt = result.data;
console.log(rt);
return rt;
});
}
return {
name: get()
};
});
The console is printing the value as "true" which is what I need. But in my controller, I am trying to print the value and it prints undefined
bookModule.controller("bookHomeController",
function ($scope, bookService, UserService, viewModelHelper, $filter) {
$scope.arabic = UserService.name;
console.log($scope.arabic);
}
Can someone help me please !!!