AngularJS: Inject controller inside another controller from the same module

前端 未结 4 1108
耶瑟儿~
耶瑟儿~ 2021-02-12 16:12

Is possible to inject a controller into another controller that is part of the same module?

example:

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-12 16:19

    You cannot inject controllers in another controllers,only serviceProviers are injectable.That's the reason you are getting error as unkown provider in controller one.

    Use Services instead and inject them in controllers,if there is some come functionality to be shared among controllers.Services are the best way to share data in between controllers.

    You can declare a variable or function or say object on $rootScope, it's exists in your whole application.

    Share data between AngularJS controllers

提交回复
热议问题