dman
dman

Reputation: 11064

Can not fire a event from a Polymer 3 Mixin

I have the below in a mixin. However, dispatchEvent is not attached to this. I get the error Cannot read property 'dispatchEvent' of undefined.

So, I used window.dispatchEvent instead but the event doesn't get caught by the parent element. Any ideas what I can do to fire a event in a mixin?

  fetchError(response) {
      ...
      this.dispatchEvent(new CustomEvent(
        'http-error', {bubbles: true, detail: msg, composed: true}
      ));
      return Promise.reject(new Error(response.statusText));
    }

Upvotes: 0

Views: 45

Answers (1)

Benny Powers
Benny Powers

Reputation: 5836

You probably need to bind the method

Add this to your mixin:

constructor() {
  super();
  this.fetchError = this.fetchError.bind(this)
}

Upvotes: 1

Related Questions