angular-visjs
angular-visjs copied to clipboard
Some events outside angular's digest cycle
Hi,
At least the 'deselectNode' occurs outside angular's digest cycle (maybe more).
I have this (stripped) setup:
this.events = {
selectNode: this.nodeSelected,
deselectNode: this.nodeSelected
};
<div vis-network events="$ctrl.events"></div>
The 'nodeSelected' roughly looks like this:
public nodeSelected = (items) => {
if (items.nodes.length) {
this.selected = items.nodes[0];
} else {
this.selected = null;
};
};
If i display the selected like this:
<pre ng-bind="$ctrl.selected | json"></pre>
It updates the selected if the 'selectNode' is triggered, but not when the 'deselectNode' is triggered, only after a new digest cycle. The current workaround I implemented is this:
public nodeSelected = (items) => {
if (items.nodes.length) {
this.selected = items.nodes[0];
} else {
this._$scope.$apply(() => {
this.selected = null;
});
};
};
What causes this issue?
I found a similar problem with the stabilizationDone callback. The following does not always trigger the $watchCollection for the options field. However, sometimes it is triggered quite late. I try to provide a JSBin.
`` $scope.graphEvents = { "stabilized": stabilizationDone }
function stabilizationDone() { $scope.graphOptions['physics'] = false; } ``