Why does HTTP service require @Injectable decorator and a custom service does not in Angular 2?

Discussão em 'Angular' iniciado por user1142130, Dezembro 2, 2024.

  1. user1142130

    user1142130 Guest

    Why is it, that I need to include @Injectable when doing DI using http, but I don't need it when doing DI using a custom service I created?

    For example:

    //no @Injectable() here
    export class Test {
    constructor(private customService: CustomService){}
    }

    /*-------------*/

    @Injectable() // <== required here
    export class HttpTest {
    constructor(private http: Http){}
    }

    Continue reading...

Compartilhe esta Página