-
Notifications
You must be signed in to change notification settings - Fork 10
doc: add section on asserting injection context in dependency injection #13
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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