doc: add section on asserting injection context in dependency injection#13
Conversation
519ab59 to
135fcfa
Compare
|
@SkyZeroZx Thank you for your contribution! I've personally never used To make sure this tip is broadly useful and not too niche or advanced (I try to keep Angular Tips accessible), could you please provide a real-world example of a helper function that would benefit from this? Thanks! |
|
The most common case, if you have several components or logic that need to access the DOM, is that instead of injecting ElementRef and then import { ElementRef, assertInInjectionContext, inject } from '@angular/core';
export function injectNativeElement<T extends Element>(): T {
assertInInjectionContext(injectNativeElement);
return inject(ElementRef).nativeElement;
} |
martinboue
left a comment
There was a problem hiding this comment.
A few minor comments, but nothing major. Thank you for your contribution ❤️
135fcfa to
8519cb7
Compare
8519cb7 to
6391c63
Compare
|
I took the liberty of changing the order of the two tips and adding the version number to the links to angular.dev, I hope you don't mind. Thanks again and congrats for being the first PR contributor of Angular Tips! 🎉 |
Add section about
assertInInjectionContext