Services - Angular (Tutorial #17)
Services are one of the part of angular which basically use for sharing of data across the angular application and we also use it to make HTTP Call. Use this link to share this video: https://youtu.be/2ZZ8ohsZcxk Sharing of data is one of the requirement in angular application. Sometimes we want to use same data across components. So to do so you have 2 approaches 1) create that data in each component individually - but there is drawback with that approach we are re-writing the code which is against the approach of DRY(DONT REPEAT YOURSELF) and code also become lengthy , complex and less testable. So next approach is Services 2) Service is a centralized location in angular application where you can keep your data which you want to share across components. Any modifications done in service will automatically reflected back to all the components who is injecting this service because services are singleton (Single instance of that service will get created) To create service use ng generate command : ng g s services/userService All services class will use Injectable() decorator because we can inject service in any component After that we need to register our service the way we have registered our component to app.module.ts in declarations. All service will registered in app.module.ts providers[] array. After registeration we need to use DI(Dependency Injection) to inject the reference of that service in any component . After DI we can call all methods define in that service class If you liked my channel , subscribe to it and like my videos. For any queries ask you question in comment section you can also connect with me @ Facebook: https://www.facebook.com/AngularJS4Beginners LinkedIn: https://www.linkedin.com/in/nisha-singla-82407aa0/ Website : http://nishasingla.com/
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.