i have a service as below
module.service('translationService', [
"$resource",
function($resource) {
var This = this;
This.params = 'HELLO';
This.getTranslation = function() {
var languageFilePath = 'sample.json';
//return languageFilePath;
$resource(languageFilePath).get(function(data) {
var temp = "";
if (This.params != "") {
angular.forEach(data, function(key, value) {
if (value == This.params)
temp = key;
});
} else {
This.translation = "Pls input key";
}
This.translation = temp;
return temp;
});
}
}
]);
In controller i am calling service,
This.translate = translationService.getTranslation();
Problem is when i debug temp has value , but when i return value becomes null. May be its inside one more function .get()
and return is losing scope. But if I return languageFilePath
as commented above (//return languageFilePath;
), value is passing to controller.
Please help me how to return value.