angular-visjs
angular-visjs copied to clipboard
get network object from controller
Hi
I need my network object in my controller. the network object is created in vis-js directive, but I need it in my controller to use it's functionality. Is there a way to do it without doing modifications in angular-visjs?
Thanks,
Yes - you can use the component=x
attribute (where x is the scope variable that you want to contain the network object.
There should also be an onload
callback, but it seems to be not available in the network directive.
Hi I saw that attribute, the problem is that it is issolated scope so I cant use it from the controller. If I connect it to $scope from the controller like this: $scope.mynetwork = {} and in the html <vis-network component=”mynetwork“> I can
t see my network from the controller. What am I doing wrong? Can you provide example?
Hmmm - I’ll take a look. I’ve not tested this method - I use the onload() callback, but this is commented out in the network (not sure why I did that)… I’ll add this event back in and see if I can work out what’s up…
I’ve added the onload() callback into the network directive - you should be able to use this to access the network object.
$scope.events = { onload: function(network) {
}
};
Thanks, I will try it.
Hi,
I think there is a copy paste error in the code for the network onload event.
// Create the graph2d object
network = new vis.Network(element[0], scope.data, scope.options);
// onLoad callback
if (scope.events != null && scope.events.onload != null &&
angular.isFunction(scope.events.onload)) {
scope.events.onload(graph);
}
It should actually be network
not graph
. The event listener in the controller needs then to be like the following.
$scope.graphEvents = {
"onload": init
};
I think there is a copy paste error in the code for the network onload event.
Thanks - this should now be fixed.
The event listener in the controller needs then to be like the following.
Yes, you can also do it this way - it's the same as I defined, but I added the definition of the callback to show the parameter