How dependency injection in Angular is useful since it doesn't solve anything apparently?

Discussão em 'Angular' iniciado por Jameela Khan, Março 11, 2025.

  1. Jameela Khan

    Jameela Khan Guest

    How this can improve my code? How it can remove dependency ? I still don't see any benefit of using this ?

    @Component({
    selector: 'talk-list',
    templateUrl: 'talks.html',
    providers: [TalksAppBackend]
    })
    class TalkList {
    constructor(backend:TalksAppBackend) {
    this.talks = backend.fetchTalks();
    }
    }


    If i had used

    TalksAppBackend t= new TalksAppBackend(); that would have been the same. Apart from syntactical difference how different it is?

    Update:

    Also, it's calling .fetchTalks(); that's not mocking. How its possible?

    Continue reading...

Compartilhe esta Página