Having trouble updating text on a page within the $scope. Facing this error message:
Error: [$rootScope:inprog] [http://errors.angularjs.org/1.2.15/$rootScope/inprog?p0=%24apply]
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:6:450
at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:101:443)
at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:108:301)
at h.$scope.changeLang (http://treenovum.es/xlsmedical/js/medical-app.js:80:16)
...
Clearly, I'm missing something. :) Any suggestions on how to resolve this? Need the page to reflect the updated variables in the scope.
Here's the code snippet for the update process:
medicalApp.controller('MainCtrl', function($scope, $cookies, getTranslation) {
getTranslation.get(function(data){
$scope.translation = data;
});
$scope.changeLang = function (lang) {
console.log(lang);
$cookies.lang = lang;
$scope.$apply(function(){
getTranslation.get(function(data){
$scope.translation = data;
console.log(JSON.stringify($scope.translation));
});
});
};
});
The HTML portion:
<body ng-controller="MainCtrl">
...
<div class="header-lang col-xs-4">
<p>
<a href="#" ng-click="changeLang('de')">DE</a> |
<a href="#" ng-click="changeLang('fr')">FR</a></p>
<div>{{ translation.text }}</div> <---- Example variable I want updated.
...
Also using ngRoute with separate controllers for different pages loaded, could that be causing the issue?