How to use 'this' in Angular with D3?

前端 未结 2 828
轻奢々
轻奢々 2020-11-28 14:15

Tldr; How do I deal with this in reference to a D3 object when Angular binds this to the class (component/service)?


2条回答
  •  日久生厌
    2020-11-28 14:57

    Try using d3.event.sourceEvent.target:

    .on('drag', () => {
      const target = d3.event.sourceEvent.target;
      const m = target.getCTM();
      const x = d3.event.x - this.clickOrigin.x;
      const y = d3.event.y - this.clickOrigin.y;
      this.setClickOrigin(d3.event);
      d3.select(target)
    

    Forked Plunker Example

提交回复
热议问题