Question:
Why does the $scope.$watch
function get called twice when I manually hide/show a column but only once when I reorder/sort columns in ng-grid?
When I specifically target a single column with the watch function, it is only called once. I suspect that on hide/show actions, the entire ng-grid is changed, while on reorder/sort, only specific columns are affected.
Is there a way to determine which events trigger the function call in each situation?
Another Question:
How can I prevent the second or first invocation of the function?
I attempted to debug certain sections of AngularJS code:
if ((watchers = current.$$watchers)) {
// process our watches
length = watchers.length;
...
watch.fn(value, ((last === initWatchVal) ? value : last), current);
...
// in the case user pass string, we need to compile it, do we really need this ?
if (!isFunction(listener)) {
var listenFn = compileToFn(listener || noop, 'listener');
watcher.fn = function(newVal, oldVal, scope) {listenFn(scope);};
}
I noticed that watchers[4]
and watchers[5]
have identical expressions (gridOptions.$gridScope.columns
), but watchers[5]
has my function as its action while watchers[4]
calls listenFn(scope)
.
My attempt to use $gridScope.renderedColumns
resulted in the same issue.