Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Angular DI Is Not Type-Safe, So I Fixed It

DEV Community·Romain Geffrault·28 days ago
#pgX8BBXs
#how#angular#typescript#services#type#service
Reading 0:00
15s threshold

According to a poll I ran on LinkedIn, there are two main ways people use Angular dependency injection. Only creating root services, meaning services are singletons shared across the whole application. Creating local services, meaning they are provided at the component, route, or module level. In that model, root services are only used when data truly needs to be shared across the app. I also got other answers with slightly different, equally valid perspectives, but the poll was still interesting, even if it only reflects my audience, which is mostly experienced developers. That leads to a few questions: Why does the first group stick to root services only? Why does the second group prefer local services? From my own experience, even though I personally prefer the second approach, I also think it is currently dangerous. If a service is not provided, Angular will fail at runtime and crash that part of the application.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More