Angular2 Beta dependency injection

前端 未结 3 886
野性不改
野性不改 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 06:37

    List the services in your bootstrap call (wherever you are handling that). Something like the following should work:

    bootstrap(App, [UserService, QApi, COMMON_DIRECTIVES, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, HTTP_PROVIDERS]); 
    providers// directives added here are available to all children
    

    Then you will have a single instance of each of those services available to the rest of your application.

提交回复
热议问题