A practical guide on how to avoid using raw global objects in Angular by wrapping external libraries (using Leaflet as an example) with Angular's InjectionToken and @Inject decorator. The tutorial covers installing Leaflet, defining a TypeScript interface for its API, creating an InjectionToken, registering it in AppModule

3m read timeFrom playfulprogramming.com
Post cover image
Table of contents
Install leaflet Copy link Link copied!Leaflet API Copy link Link copied!Use the InjectionToken Class Copy link Link copied!Provide the Leaflet Copy link Link copied!Using @Inject Copy link Link copied!That's it! Copy link Link copied!

Sort: