praveenpds praveenpds - 6 months ago 30
AngularJS Question

Different kind of Angular Directives patterns

angular.directive('ppd:reset', function(e1,e2) {
return function(linkElement) {


angular.directive('ppd:reset', [function() {
return function(scope, elm, attrs) { }


What is the difference between these two directives pattern ?

Answer Source

If you declare your factories with the bracket notation, you can avoid problems when minifying your code:

angular.directive('ppd:reset', ["$compile", function(compile) {
    return function(scope, elm, attrs) {   } 


The injector looks at your function parameter names in order to know what to inject. If a minification process renames those, The injector doesn't know what to do anymore. Minification will of course not touch string values which is why the array notation works fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download