Badge elements have the style 'pointer-events: none', which is why you don't get the click events. You can use Javascript to query the inner implementation element and change this style.
So for the following HTML:
<div id="todo-actions" matBadge="!" matBadgeOverlap="false" matBadgeColor="warn"> </div>
this code will do the trick:
const todoBadge: HTMLElement = document.querySelector("#todo-actions .mat-badge-content");
if (todoBadge) {
todoBadge.style.pointerEvents = "inherit";
}
Note that the .mat-badge-content
is the inner element created by the matBadge
directive. Using #todo-actions .mat-badge-content
ensures that the CSS style is changed for the specific badge element.
Finally, if you're using Angular, put the JS code in your AfterViewInit
handler.
Only drawback with this approach is that it's susceptible to break if the matBadge
implementation changes as that can happen during major framework overhauls.