question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lost event listeners

See original GitHub issue

Hi,

first of all, thank you for porting the charts into angular’s world.

I’ve got issue, when data are append after a chart creation. I’m using Object.create() in my subscribe’s callback to re-draw the chart with new options, what causes the method from (chartSelect) isn’t called.

Am I doing wrong or is it a bug?


scrap of code for reference:

export class Component {
    activityChartOptions: any;

    constructor(private service: Service) {
        this.activityChartOptions = require('./charts/activity.json');
    }

// ...

    private fetchStats() {
        this.service.get().subscribe((result) => {
            this.activityChartOptions = Object.create(this.activityChartOptions);
            this.activityChartOptions.dataTable = result;
        });
    }      
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
felipecespedescommented, Jun 7, 2017

There is a bug when registering events on a loaded chart, I’ve created a pull request to fix it #31

0reactions
Fellachcommented, Jun 6, 2017

HI again.

I took the code from your demo and modified the app.component.ts a little to simplify and to simulate an API call. As I’ve described above listener stops working, when data are re-created.

Cheers!

export class AppComponent {

 public selectEvent: ChartSelectEvent;

 public lineChartData:any =  {
    chartType: 'LineChart',
    dataTable: [
      ['Year', 'Sales', 'Expenses'],
      ['Year', 0, 0],
    ],
    options: {title: 'Company Performance'}
  };

  ngOnInit() {
    setTimeout(() => { // eg. API call

      this.lineChartData = Object.assign({}, this.lineChartData, {
          dataTable: [
            ['Year', 'Sales', 'Expenses'],
            ['2004',  1000,      400],
            ['2005',  1170,      460],
            ['2006',  660,       1120],
            ['2007',  1030,      540]
          ]
      });

    }, 1000);
 }

  public select(event: ChartSelectEvent) {
    this.selectEvent = event;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Losing Event Listeners on Function Recall - javascript
I checked DevTools and the created elements prior to that lose the click event when I execute the function again.
Read more >
Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
Read more >
Javascript - How to list all active event listeners on a Web page
Javascript - How to list all active event listeners on a Web page, events defined by addEventListener or in an event attribute.
Read more >
Element: focusout event - Web APIs | MDN
The focusout event fires when an element has lost focus, after the blur event. The two events differ in that focusout bubbles, while...
Read more >
Event Handlers for DOM Event Listeners Lose the Context ...
Given that the event handler is an instance method, the reference to its object instance should be preserved. If the issue cannot be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found