illustration for Angular Service Injection with the Dependency Injector (DI)

Angular Service Injection with the Dependency Injector (DI)

46m closed-captioning
Star icon$$$
Star icon$$$
Star icon$$$
Star icon$$$
Star icon$$$
4.6
649
people completed
Bookmark
Download
RSS

Note: This course is still valid for Angular ^17 but the set up has changed.

Services and registering service providers are an inherent part of an Angular application. It is where you should define your application logic, they keep the state of the application and allow to share that among different components.

That said, components can ask for instances of services by specifying them as parameters of their constructor functions which will then provided at runtime by Angular’s dependency injection mechanism. While services themselves are mostly just plain ES2015 classes, there are some interesting things to discover, especially when it comes to dependency injection.

We can define services at various levels within our application, which allows us to control the scope and visibility of a given service. We can furthermore alias old service definitions to new, existing services which is handy for refactoring scenarios and we also have the possibility to define so-called factory functions for fully taking control of how a given service is being constructed.

In this course we will take a closer look and walk step by step through all of these scenarios.

Learner Reviews

  • Learner
    2 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What did you like about this course?

    its good and all the concepts are clear.

  • Rahul Singh
    4 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What did you like about this course?

    in depth explanation of angular services, really appreciate your work towards the community.Thank you

  • Aleksandar Benic
    4 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What would make this course a 7 for you?

    Because there is only how to use something and not why and what is best use-case.

  • Ayush Gupta
    5 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What did you like about this course?

    This course goes soooo much into deep concepts! I did not expect such a fine grained details in the course. Specially the lesson when he demonstrated the useExisting property, I was like "hey we can use useClass can't we? He told it's the same usage." And Juri started saying "you might be wondering why we didn't use useClass?" That is getting into the head of the student which every instructor should be able to.

  • NewsWhip
    5 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What would make this course a 7 for you?

    This may be out of scope for this course, but some real-world use cases for @Optional, @SkipSelf and @Host would be useful. I can't think of any that make sense.

    To me @Host is redundant. If you have your dependency in the providers array of the component, it's essentially retrieving the dependency from the host. Adding the host @Host decorator on top of this won't do anything. Is it only useful as a sanity check to ensure the dependency is provided in the component?

    I also have trouble with the use case for @Optional. On the face of it it seems like a way to workaround an injection error - I've always viewed DI as a contract or guarantee that these dependencies will be available.

  • Joseph Raj
    5 years ago
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    Star icon$$$
    What did you like about this course?

    The way of Juri's explaining is great. Telling the scenario and we can overcome that scenario is a great way helps in apply the learned material into our realtime projects at works Thank you very much for your effort Juri

Course Content

46m • 14 lessons

    You might also like these resources:

    illustration for Introduction to Cloudflare Workers

    Introduction to Cloudflare Workers

    Kristian Freeman・36m・Course

    Become familiar with the Workers CLI wrangler that we will use to bootstrap our Worker project. From there you'll understand how a Worker receives and returns requests/Responses. We will also build this serverless function locally for development and deploy it to a custom domain.

    illustration for Create an eCommerce Store with Next.js and Stripe Checkout

    Create an eCommerce Store with Next.js and Stripe Checkout

    Colby Fayock・1h 4m・Course

    This is a practical project based look at building a working e-commerce store using modern tools and APIs. Excellent for a weekend side-project for your developer project portfolio

    illustration for Practical Git for Everyday Professional Use

    Practical Git for Everyday Professional Use

    Trevor Miller・1h・Course

    git is a critical component in the modern web developers tool box. This course is a solid introduction and goes beyond the basics with some more advanced git commands you are sure to find useful.