New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Namespaced Custom Events #28491
Comments
Here is where it does the parsing: packages/compiler/src/template_parserbinding_parser.ts#L335 Edit: Something like this would work: let target: string | null = null;
let eventName: string;
if (name[0] === '^') {
eventName = name.slice(1)
else {
([target, eventName]) = splitAtColon(name, [null !, name]);
} |
If anyone lands here in the future, I came up with this ugly work around. import { DOCUMENT, EventManager, EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
class RewriteEventManagerPlugin {
manager: EventManager;
constructor(private _doc: Document) {
}
supports(eventName: string): boolean {
return eventName.indexOf('@') !== -1;
};
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
return this.manager
.addEventListener(element, eventName.replace('@', ':'), handler);
}
}
@NgModule({
...
providers: [
{
multi: true,
provide: EVENT_MANAGER_PLUGINS,
useFactory(document: Document) {
return new RewriteEventManagerPlugin(document);
},
deps: [DOCUMENT]
}
]
})
class MyModule {} <!-- the @ symbol will be replace with a ":" when the event listener is added to the element -->
<mwc-tab-bar (MDCTabBar@activated)="onTabActivated($event)"></mwc-tab-bar> |
As |
@robwormald In that sense, |
Would love to have a PR for this (as well as a test) |
Re-confirming what was already said - an event with The bad part here is that Angular uses |
Any updates? We make extensive use of Lit web components on https://shop.battle.net/ which emit events that contain |
I found a workaround! Looking at the code, I noticed _splitAt() only checks the first instance of Using the example from the OP, the workaround looks like:
|
馃悶 bug report
Affected Package
platform-browser
Is this a regression?
No.Description
Custom events that are namespaced using the syntax
namespace:event
will fail. For example, binding to theMDCTabBar:activated
event will fail (source).The problem is Angular will think you are listening to an
activated
event on a globalMDCTabBar
event target (source).Possible Solution
If Angular doesn't know about the event target then assume it is part of the event name, or add syntax to tell Angular to listen to the event name verbatim. I think I saw the
^
syntax in another issue.e.g.
馃敩 Minimal Reproduction
Not needed.
馃敟 Exception or Error
馃實 Your Environment
Angular Version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: