How to register & dispatch a event #6655
Answered
by
chrisdholt
zhaoyiming0803
asked this question in
Q&A
🐛 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
|
Answered by
chrisdholt
Mar 2, 2023
Replies: 3 comments
|
I suggested we contribute that to the docs in #6638 |
0 replies
|
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)
}
} |
0 replies
|
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. |
0 replies
Answer selected by
KingOfTac
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.