Angular2 Beta dependency injection

前端 未结 3 930
野性不改
野性不改 2021-01-14 06:26

I have a NavBar Component which loads the QApi Service, the QApi Service loads the UserService, but I get the following error:

EXCEPTION: No provider for Use         


        
3条回答
  •  我在风中等你
    2021-01-14 07:03

    Add UserService to the component providers:

    @Component({
        selector: 'nav-bar',
        template: `Test NavBar`,
        providers: [QApi, UserService] // <- add UserService here
    })
    export class NavBarComponent { /* ... */ }
    

    Here are two good articles to better understand Angular2 Dependency Injection:

    • blog.thoughtram.io: Dependency Injection in Angular2
    • blog.thoughtram.io: Injecting services in services in Angular 2

提交回复
热议问题