angularjs - .config, .run, AppCtrl - where to put routes? -
i wanted find out difference between .config , .run functions in angularjs. using .config setting routes, did have $on's watching route change start , success events.
i moved of code .run having dependency injection problems in .config.
i moved of commonappcontroller have set on <body>.
i had 2 .config's , seemed running ok, surely isn't right?
can give little insight on method use?
configuration blocks , run blocks executed @ different points in application bootstrap, , have different injection locals @ disposal. here's summary of can find in angularjs documentation.
configuration blocks (registered module.config()) executed during provider registration, , can injected providers , constants (see module.provider() , module.constant()). typically configure application-wide stuff, such $routeprovider. stuff needs configured before services created.
run blocks (registered module.run()) executed after injector has providers. now, instances , constants can injected. typically configure services, $rootscope, events , on.
you can have multiple of either, , executed in order registered module. people prefer register configuration block before every group of controllers register routes these controller, example.
Comments
Post a Comment