angularjs - Angular Directive: Dependencies on directive vs dependencies on directive controller -


it seems there two ways declare dependencies re: directives

directly on directive function call -- i'll call "directive directly" style:

.directive('mycurrenttime', ['$interval', 'datefilter', function($interval, datefilter) {... 

on controller option of directive object returned function call -- i'll call "directive's controller" style:

controller: ['$scope', function mytabscontroller($scope) {... 

what's difference? when should use "directive directly" style vs "directive's controller" style?

here guesses: if use "directive directly" style, dependencies available link function. if use "directive's controller" style, controller allows "inter-directive communication"

so that's conclusion:

  • if need controller "inter-directive communication" ...
  • and don't need dependencies available in link function...

then use "directive's controller" style...

as i've been (over)thinking angular lately, confused. example, can think of 10 ways 1 thing, , spend more time wondering technique best coding final solution...

when confused , use these touchstone criteria make decisions. maybe can tell me whether of these better served 1 or other. (if don't agree these goals/criterias, or there no difference re: criteria, ignore them)

  • readability
  • maintainability
  • testability
  • similarity/portability angular 2
  • performance


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -