Sometimes while loading the page, translateChangeSuccess
is not getting fired and its throwing error.
So, I need to call the $translateChangeSuccess
whenever the $translate is ready. How to do it in a proper way?
This is not working.It is not entering the '$translateReady' function.
$rootScope.$on('$translateReady', function () {
console.log("It enterd Translate ready"+$translate.isReady());
$rootScope.$on('$translateChangeSuccess', myfunction());
});
But if i use this funtion it is entering inside the function
$translate.onReady().then(function() {
console.log("It enterd Translate ready"+$translate.isReady());
$rootScope.$on('$translateChangeSuccess', myfunction());
});
I need to call $translateChangeSuccess
whenever it is Ready. How can I do ? If anyone knows please do help.Thanks!
You can broadcast if on the root scope and listen to it on whatever scope you want. Also, you don't have to call it inside the previous event handler, actually what you are doing is adding an event listener (aka $translateChangeSuccess
) when $translateReady
fires.
Anyways, consider using this way:
$translate.onReady().then(function() {
console.log("It enterd Translate ready"+$translate.isReady());
$rootScope.$broadcast('$translateChangeSuccess');
});
$rootScope.$on('$translateChangeSuccess', myfunction);
function myfunction(){
console.log("myfunction called");
}