angularjs - When a service is injected into a parent controller should I also inject into the child or just inherit the service -
I am trying to understand how a service will bring in the controller, when service parents and children are both controller and Is it used in the parents and children HTML? Should I be brought to the service in the parents and then get a copy of this kind of service in a child like this:
I would appreciate any advice and suggestions on which to be the best way to do it and if the difference is another question. Should the criteria be declared private or public on my constructor?
This is your choice, however you want to do this, but to include it directly in each controller One argument for this is that you do not have any other dependencies.
It is inherited and inherited by AppController
, that if for any reason a developer decided that "we do not mess up here yet ", Then you have all other controllers who believe that the service is breaking. - @bassarrat tells me that the typewriter will actually fail to compile, but it is clearly not much more than a problem, in this scenario, you have to keep it back, or go to every controller, in which A compilation error has been given and they are injected into it, so that you will end up again on the first solution.
By adding this directly to each controller, if you remove one of them, then it does not matter to the rest of the app. It just keeps things slightly safe.
If you really want to include it only once and want to use it everywhere, then you should be able to use the angular run
method to inject it Junk area When the app runs, you can do something like the following. $ MyApp.run (function ($ rootScope, myService) {$ rootScope.myService = myService;}) // To declare my service to be present at all frequencies: $ area: module Ng {Export Interface ISKP {myService: MyService; }}
Comments
Post a Comment