angular-ui/ui-codemirror

Initial options do not get set due to $digest equality checks

43081j opened this issue · 0 comments

If you create a directive which has a template like so:

<div ui-codemirror ui-codemirror-opts="opts"></div>

In your link function, you can setup $scope.opts and would expect this to take effect.

However, it does not, because the method here will get newValues === oldValue. This means the initial digest will set no options.

The reason this happens is the following code inside angular's $digest:

watch.fn(value, ((last === initWatchVal) ? value : last), current);

On initial digest, last === initWatchVal, so you will receive value as both parameters and never set any codemirror options until the second iteration/change.

A workaround for now seems to be to set the options as some empty object, then set the real object in the next iteration/digest.