Provide an Angular Service on a route!

  Рет қаралды 3,801

Deborah Kurata

Deborah Kurata

Күн бұрын

Пікірлер: 48
@ahmedlight7669
@ahmedlight7669 10 күн бұрын
Deborah ! You are sharing wonderful concepts ❤
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you so much!
@winnemucca-sk5392
@winnemucca-sk5392 8 күн бұрын
Thank you. I have played with this concept and even used it. I appreciate your efforts to explain routing services compared to components and root.
@deborah_kurata
@deborah_kurata 5 күн бұрын
It's been a good reminder for me as well, evaluating how each of the different cases work. 😊
@LinkingTheWorlds
@LinkingTheWorlds 10 күн бұрын
Thank you so much Deborah, the clarity of your tutorials is pure pleasure.
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you so much!
@leonidesmuguercia4211
@leonidesmuguercia4211 10 күн бұрын
Excelente video. Like always!!
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you! 😊
@ivanmaglica264
@ivanmaglica264 10 күн бұрын
I've done that mistake, provided service from multiple points and then cursed when I saw two service instances. Learned my mistake...
@deborah_kurata
@deborah_kurata 10 күн бұрын
Yep! Me too. 😅
@karthikeyanpandian1330
@karthikeyanpandian1330 9 сағат бұрын
Good knowledge sharing video and am a great fan of you since your Angular 2 course in Plural Sight 🙂 I have a question on this video: Services provided in the providers array of a route are instantiated when the route is activated. These services are scoped to the route and its child routes. When the route is deactivated (e.g., when navigating away from the route), the services are destroyed. How come it maintains the state of the service after you toggled back to the Home route? How come the life time of the service instance is the lifetime of the application after its initialized.
@radthenone
@radthenone 10 күн бұрын
Deborah you are awesome
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you! All the best to you!
@julienr8114
@julienr8114 10 күн бұрын
As always clear and understanding thank you so much. I have a little question, for route injection there is the same number of instances as defined in providers ? for example [ { path: 'vehicules-route-1', component: VehiculeComonent, providers; [VehiculeService] }, { path: 'vehicules-route-2', component: VehiculeComonent, providers; [VehiculeService] } ] then there 2 instances (each one with a state) of VehiculeService ? one for route vehicules-route-1 and a second for vehicules-route-2 ?
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you for the kind words. Yes, each provider defines another instance. I forked the sample application and changed it to this scenario. (It isn't pretty, but it demonstrates the concept). If you open the console, you can see that each page loads it's own copy of the vehicle data. Then each separately retains its own "selectedVehicle". Here is the link: stackblitz.com/~/edit/providing-services-multiple-route-deborahk Did I correctly understand your scenario?
@julienr8114
@julienr8114 10 күн бұрын
@@deborah_kurata Yes, you completely answered my question, thank you very much for taking the time to answer. This is a really great feature.
@jonatabiondiJsLover
@jonatabiondiJsLover 10 күн бұрын
Super. Please more video on Di. it is a very long and important topic
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you! Are there any specific things about DI that you are interested in seeing?
@Danshif
@Danshif 11 күн бұрын
Hi, great video, can you share a real-world example of when it’s better to use provideIn: 'route' instead of provideIn: 'root'?
@codeSurvivor
@codeSurvivor 11 күн бұрын
When you need two different instances of the same service for different routes. For example, one route for flying vehicles and another one for landing vehicles.
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you! In addition to the example provided by codeSurvivor ... (here is a detailed example of that: medium.com/@yousafrazaravian/angular-route-level-providers-a-comprehensive-guide-094b6a247557) Say you have a route specifically for administrators and they have some specialized services. By defining those services on the route accessible only to administrators, you minimize the possibility of those services accidentally being injected into any other part of the codebase. In general, it can help keep responsibilities separated. A developer on the team needs to add a set of features/routes around StarWars films (separate from vehicles). To minimize changes, the first thought it to throw the code for those features in the Vehicle Service. But the Vehicle service is only injectable on the vehicles route. So they instead must create a Films Service thus keeping the code a bit better organized. But keep in mind, that there is no issue with using provided in 'root' for the majority of your services.
@antondoit
@antondoit 10 күн бұрын
Fantastic
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thanks! 😊
@richarddefortune1329
@richarddefortune1329 10 күн бұрын
Hey Deborah, great video (as usually). I knew for "root" and "component". Is providing services in route a new angular feature? I'm struggling to see its usefulness if we can also provide in component, which will make the service available to the child components. I'm sure the angular team has a good reason for allowing both techniques. Thank you again.
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you for the kind words. I *think* that provided in route was a new feature in Angular v14?? If you need different "versions" of the service for different purposes. (here is a detailed example of that: medium.com/@yousafrazaravian/angular-route-level-providers-a-comprehensive-guide-094b6a247557) Or, say you have a route specifically for administrators and they have some specialized services. By defining those services on the route accessible only to administrators, you minimize the possibility of those services accidentally being injected into any other part of the codebase. In general, it can help keep responsibilities separated. A developer on the team needs to add a set of features/routes around StarWars films (separate from vehicles). To minimize changes, the first thought it to throw the code for those features in the Vehicle Service. But the Vehicle service is only injectable on the vehicles route. So they instead must create a Films Service thus keeping the code a bit better organized. But keep in mind, that there is no issue with using provided in 'root' for the majority of your services. 😊 EDIT: I added this information to the video notes for future reference.
@richarddefortune1329
@richarddefortune1329 10 күн бұрын
@deborah_kurata thanks so much for the explanation. I feel special for the "personalized tutorial" 😇 I suppose the next logical step will be a video on new routes. It looks like they are no longer just simple json. You can use methods (matcher???). Maybe that's another use case of injecting a service in routes then use it there. I don't remember where I saw that. Thank you again for the video
@deborah_kurata
@deborah_kurata 10 күн бұрын
@@richarddefortune1329 Are you referring to this: angular.dev/guide/routing/routing-with-urlmatcher#configure-your-routes-for-your-application
@richarddefortune1329
@richarddefortune1329 10 күн бұрын
@@deborah_kurata yes. That's the one.
@rkrao8582
@rkrao8582 10 күн бұрын
Hey , Thanks for the videos on Angular and Signals. I am a subscriber to your Pluralsight course which is really good. Although it seems most of your content retired there! Do you plan on creating more updated courses? Thanks
@deborah_kurata
@deborah_kurata 10 күн бұрын
Thank you for watching! Pluralsight won't allow me to update "Angular: Getting Started" because they say they already have an "Angular Fundamentals" course. Most of my courses that have been retired have been replaced with other courses by other authors. I can provide you the link to the newer course if you let me know which topic you are interested in. At this time, I have no contract with Pluralsight for more courses.
@Ghost2012qte
@Ghost2012qte 10 күн бұрын
How can I make a service lazy-loaded if I use standalone components instead of modules? Will using loadComponent and providing the service in the route achieve this?
@deborah_kurata
@deborah_kurata 10 күн бұрын
I have a video on that here: kzbin.info/www/bejne/jKu8g3mCo9Otoac
@radthenone
@radthenone 10 күн бұрын
i liked signals but i must to use rxrj still
@deborah_kurata
@deborah_kurata 10 күн бұрын
Can you use rxJS *with* signals? That's how rxResource works...
@ruekkart
@ruekkart 10 күн бұрын
Is this like provide a service in a module and share it across all components in that module?
@deborah_kurata
@deborah_kurata 10 күн бұрын
Yes. But it's been a while since I've worked with modules. I don't recall the lifetime of services provided in a module. I assume they were also for the lifetime of the application.
@gestoeber
@gestoeber 9 күн бұрын
what happens if two routes provide the same service? Does every route get a new instance?
@deborah_kurata
@deborah_kurata 8 күн бұрын
Yep! I have an example of that here: stackblitz.com/~/edit/providing-services-multiple-route-deborahk
@glazevolda823
@glazevolda823 8 күн бұрын
Could you tell me please, is there any way to destroy VehicleService (clear it from the memory) after the user leaves the Vehicle page?
@deborah_kurata
@deborah_kurata 5 күн бұрын
Yes! Provide the service on the component instead of on the route. Then the service will be destroyed when the user leaves the page. See this video for more information: kzbin.info/www/bejne/gWGUoHepjLd2e7M
@glazevolda823
@glazevolda823 5 күн бұрын
@ , great! 🤩 Thank you so much ❤️
@BoZoM242
@BoZoM242 9 күн бұрын
What happens if a route is lazy loaded? Does it behave the same?
@deborah_kurata
@deborah_kurata 8 күн бұрын
It should, yes. The only difference would be when the *code* is loaded.
@MiguelAngelMartinezJerez
@MiguelAngelMartinezJerez 8 күн бұрын
👋👋
@deborah_kurata
@deborah_kurata 8 күн бұрын
🙏🏼🙏🏼😊
@sidvlogs3107
@sidvlogs3107 11 күн бұрын
@deborah_kurata
@deborah_kurata 10 күн бұрын
🙏🏼
Signals in Action: Passing Parameters when issuing an HTTP Request
10:22
LinkedSignal in Angular 19: The Gem We Were Missing
14:05
Decoded Frontend
Рет қаралды 7 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
Setting Up a Bug Bounty Methodology (Live Session) 💻🔍
5:11:05
Bug Bounty World
Рет қаралды 122
A Redux-like Pattern for Managing State with Angular signals
17:51
Deborah Kurata
Рет қаралды 15 М.
Angular 19 New Exciting Features! #angular #coding #software
6:01
Michael Olech Coding
Рет қаралды 1 М.
10 Signs Your Software Project Is Heading For FAILURE
17:59
Continuous Delivery
Рет қаралды 36 М.
Why is every React site so slow?
13:52
Theo - t3․gg
Рет қаралды 144 М.
7 Design Patterns EVERY Developer Should Know
23:09
ForrestKnight
Рет қаралды 284 М.
Javascript's New Pipeline Operator Is Awesome!
7:26
Jack Herrington
Рет қаралды 52 М.
This confused me as a TypeScript Beginner
5:37
Andrew Burgess
Рет қаралды 9 М.
Build Generalized DRY Angular Code with Generics
14:44
Deborah Kurata
Рет қаралды 13 М.