krispo / ng2-nvd3

Angular2 component for nvd3
http://krispo.github.io/ng2-nvd3/
MIT License
328 stars 104 forks source link

bar chart dispatch event #115

Closed reymondVillaluz closed 6 years ago

reymondVillaluz commented 7 years ago

Hi,

I am trying to call an angular 2 method on the elementClick on multibar is that possible? I am using angular 2 type script and ng2-nvd3. console.log and alerts are working properly but when I am trying to log a angular 2 variable./method it is undefined.

here is the sample code:

multibar: { dispatch:{ elementClick: function(t, u){ console.log(this.somevariablename); //alert('click event is fired! data: ' + t['data'].value); } } } Thanks!

Prashanth-Thomas commented 7 years ago

@reymondVillaluz Looking for a similar solution. Found anything?

Prashanth-Thomas commented 7 years ago

@reymondVillaluz if you want to call an angular2 method from an elementClick event. try using the arrow function.

multibar: { dispatch:{ elementClick: (e) => { console.log(this.somevariablename); //now you can access this.variables and this.methods related to your component. } } }

Moulde commented 7 years ago

@reymondVillaluz Did the solution work for you? - if yes, can you close the issue? :)