0

Hello I'm trying to write some d3.js code inside of an Angular 2 components. For the visualization to work I'm trying to bind some data to the svg elements themselve using the "this" accessor inside the d3.js function

slices.transition()
            .attrTween("d", (d: DataSet) => {
                console.log((<any>this));
                // do something with the this variable
            });

Now the problem is that the "this" variable is pointing to the Angular 2 component object. I'm trying to access the svg element which is creates by d3.js.

Is there any other way to access this variable?

Politiepet
  • 93
  • 1
  • 2
  • 11
  • 1
    Just closed as a duplicate. Essentially, you can't use "far arrow" notation as `this` doesn't get set to the element being operated on. Instead use a conventional function: `.attrTween("d", function(d: DataSet) { ` – Mark Jan 15 '17 at 15:01
  • 1
    Wow, thanks. Didn't really run into any situation where I had problems with the "this" variable in arrow functions, so I didn't realize this could be the problem. Thanks for the quick answer, solved it for me! – Politiepet Jan 15 '17 at 15:03

0 Answers0