Reputation: 11064
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
Reputation: 5836
You probably need to bind the method
Add this to your mixin:
constructor() {
super();
this.fetchError = this.fetchError.bind(this)
}
Upvotes: 1