I´m trying to understand promises in Angular. But I'm still mixing concepts. Please have a look at the following example in Angular 1.0.7:
// After locale is set code should be executed
initLocale(language).then(function (result) {
console.log("Insert code here");
});
Can someone can help me to understand why this code is working:
var initLocale = function(language) {
return $translate.uses(language);
};
And this code is not:
var initLocale = function(language) {
$translate.uses(language).then(function(result) {
// I need to do things here! For example call another
// Asynchronous function.
tmhDynamicLocale.set(language).then(function () {
console.log("Locale started!");
});
return result;
});
};