angular-visjs icon indicating copy to clipboard operation
angular-visjs copied to clipboard

get network object from controller

Open oriko opened this issue 9 years ago • 7 comments

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,

oriko avatar May 26 '15 14:05 oriko

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.

cdjackson avatar May 26 '15 14:05 cdjackson

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 cant see my network from the controller. What am I doing wrong? Can you provide example?

oriko avatar May 26 '15 18:05 oriko

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…

cdjackson avatar May 26 '15 18:05 cdjackson

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) {

}

};

cdjackson avatar May 26 '15 18:05 cdjackson

Thanks, I will try it.

oriko avatar May 28 '15 08:05 oriko

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
};

Tooa avatar Jun 13 '15 10:06 Tooa

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

cdjackson avatar Jun 27 '15 08:06 cdjackson