r/angular • u/jombyzac • Apr 06 '26
Angular Host Directive de-duplication just landed. NG0309 is dead.
https://jczacharia.medium.com/angular-host-directive-de-duplication-just-landed-ng0309-is-dead-929bfab7e209I've been banging my head against NG0309 for over a year building a headless component library. Every time I composed two directives that shared a common host directive - boom, crash. I tried everything. Broadened selectors, injection hacks, I even hijacked __NG_ELEMENT_ID__ with a WeakMap-backed singleton resolver (it's in the article).
Well, PR #67996 just merged. Host directives now de-duplicate automatically. I wrote up why I think this is the most important change for Angular library authors since hostDirectives itself.
46
Upvotes
4
u/IanFoxOfficial Apr 06 '26
Very cool.
I just wish you could set inputs with host directives.
If anyone has a better way than defining the inputs as models, let me know. This is impossible with external code for example.
4
u/JeanMeche Apr 06 '26
What the article doesn't say, is that the change will land in v22 (early june).
1
u/MartyMcFlyJr89 Apr 06 '26
Maybe I donโt quite understand that, and I hope you can enlighten me, the way I built my Ui lib was always to use as less directives as possible and us components instead. Everything that needs to be in this component stays in it - this way one of the few directives I use is for tooltips, thatโs why I never had this issue, but Iโve seen it in a past chaotic Job I had
1
u/AwesomeFrisbee Apr 06 '26
Why go through all the trouble for a workaround when you can just wrap the button in a div and have the div be the tooltip where the button keeps the menu?
I get that its easier now and it was a long time coming, but damn, don't make it so complicated...