I'm having refresh issues with a localization filter. When the file is loaded, the view do not get refreshed. I've tried $scope.$apply()
and $filter("localization")(localizationService.text)
, neither is working.
localizationService :
angular
.module("myApp")
.factory("localizationService", function () {
var service = {
text: null,
language: "en"
};
return service;
});
localization filter :
angular
.module("myApp")
.filter("localization", function(localizationService) {
return function (value) {
if (localizationService.text && localizationService.text.hasOwnProperty(value)) {
return localizationService.text[value];
}
return value;
}
});
controller refreshing automatically the file to use :
$scope.$watch(function () {
return $location.path();
}, function () {
var fileName = "../Localizations/" + $location.path().substring(1) + "/localization-" + localizationService.language + ".json";
$http.get(fileName).then(function (response) {
localizationService.text = response.data;
//$filter("localization")(localizationService.text);
//$scope.$apply();
});
});
localization-en.json :
{
"test": "this is working !"
}
HTML :
<div>{{'test' | localization}}</div>
This code writes test
instead of this is working !
.
How can I fix this ?
$scope.$apply();
says :$digest already in progress
... – Whoa