Dependency injection in Angular | Services & Dependency Injection

In the last lecture we learned that creating an instance of a service by our own is not a good practice. Instead we can ask angular to inject an instance of a service in the component where we want to use it. This is called as dependency injection.
Dependency injection is a concept where another source injects a dependency of a class to that class, making the class loosely coupled with dependent class.
Let's leran with an example, how we cen inject a dependency to a component in this lecture.

Пікірлер: 13

  • @tsvetanabogdanova2342
    @tsvetanabogdanova23422 жыл бұрын

    Very easy to understand from your explanation. Thank you.

  • @sarbjitkaur5070
    @sarbjitkaur50702 жыл бұрын

    U made it pretty easy to understand DI concept. Thanks!

  • @najmahussaini1423
    @najmahussaini14237 ай бұрын

    auf Deutsch sagt man "Kurz und Knackig"! Well explained, Thank You!

  • @klirmio21
    @klirmio2111 ай бұрын

    amazing tutorial, way better than the official google's tutorial

  • @whyjustwhy9507
    @whyjustwhy9507 Жыл бұрын

    the explanation was clear and understood, good job!

  • @mohiburrahman5639
    @mohiburrahman5639 Жыл бұрын

    perfect class!! for services!!

  • @zsombordomjan7808
    @zsombordomjan7808 Жыл бұрын

    friend u r a genius i love you

  • @maheshsirsat1811
    @maheshsirsat181111 ай бұрын

    Great

  • @kabhishek4961
    @kabhishek4961 Жыл бұрын

    sir why did you use accessspecifier as private for instantiation variable..??

  • @fermisurface2616

    @fermisurface2616

    Жыл бұрын

    That's a Typescript shortcut that saves you from doing something like private service: Service; constructor(service: MyService){ this.service = service; }

  • @PriyaM-yo5by
    @PriyaM-yo5by Жыл бұрын

    Hello sir, Actually I been little bit confused. you have given the service file inside provider, then why youre importing the service file again using import keyword. Then i didnt understand the purpose of providers. can somebody help me,if u know the concept?

  • @fermisurface2616

    @fermisurface2616

    Жыл бұрын

    You have to import the service in the component file so the compiler knows what that class keyword means (otherwise it would say that the class isn't defined). Injecting gives you an actual instance of that class to use. They are two different concepts.

  • @fermisurface2616
    @fermisurface2616 Жыл бұрын

    No more capitalized function names 😞

Келесі