thrag thrag - 4 months ago 56
AngularJS Question

RangeError: Maximum call stack size exceeded

I guess this means there is a circular reference somehwere but for the life of me I can't guess how to fix it.

Anyone have any ideas?

http://plnkr.co/edit/aNcBcU?p=preview

Check the debug console in Chrome (for example) and you'll see the error.
The offending line is

scope.map = map;


scope.map is being "$watched" on the controller via

$scope.$watch("options.map", function (map) { ... }, true);

Answer

It's because you're comparing for object for equality rather than for reference. Change your $watch statement to this:

$scope.$watch("options.map", function (map) {
    if (map === undefined) {
        alert("map has no value");
    } else {
        alert("map is defined");
    }
});