How to register & dispatch a event #6655
-
🐛 Bug Report💻 Repro or Code Sample🤔 Expected Behavior😯 Current BehaviorHow can i register a custom event, and dispatch it in the How to receive messages that trigger by <my-tag onChange="onChange"></my-tag> 💁 Possible Solution🔦 Context🌍 Your Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I suggested we contribute that to the docs in #6638 |
Beta Was this translation helpful? Give feedback.
-
The following codes can work, actually, i want to register & trigger a <footer-tag slot="footer" id="footer-tag"></footer-tag> const footerTag = document.querySelector('#footer-tag')
footerTag.addEventListener('on-change-footer-greeting', (e) => {
console.log('on change footer greeting: ', e.detail)
}) My @customElement({
name: 'footer-tag',
template,
styles
})
export class Footer extends FASTElement {
greetingChanged () {
const customEvent = new CustomEvent('on-change-footer-greeting', {
detail: {
greeting: this.greeting
}
})
this.dispatchEvent(customEvent)
}
} |
Beta Was this translation helpful? Give feedback.
-
Take a look at this line: You can use the emit helper to emit a custom event with a name, and you can pass back additional information (the event object if available as an example). FYI, I’m going to convert this to a discussion as it seems more question related than an actual issue. |
Beta Was this translation helpful? Give feedback.
Take a look at this line:
fast/packages/web-components/fast-foundation/src/tree-item/tree-item.ts
Line 68 in 4e17af8
You can use the emit helper to emit a custom event with a name, and you can pass back additional information (the event object if available as an example).
FYI, I’m going to convert this to a discussion as it seems more question related than an actual issue.