I'm facing an infinite loop when trying to make AngularJS display a promise, as explained in this article: http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/.
I first call $parseProvider.unwrapPromises(true);
:
.config(["$parseProvider",
function($parseProvider) {
$parseProvider.unwrapPromises(true);
}])
Here is the factory I use to access a message:
app.factory("MessageHelper", [
function() {
// omitted for brevity:
// calling the server for getting the messages
return {
get: function(code) {
var args = Array.prototype.slice.call(arguments);
args.shift();
if (messages) {
return $q.when(format(messages[code], args));
}
var deferred = $q.defer();
deferredMessages.push({ code: code, args: args, deferred: deferred });
return deferred.promise;
}
};
}]);
Then, in a controller:
$scope.msg = {
get: function() {
return MessageHelper.get.apply(this, arguments);
}
};
Finally, in a view:
<span>{{msg.get("existing.message.code", "first param", "second param")}}</span>
And here is the infinite loop: $scope.msg.get
gets called infinitely... Any idea why?