mcbjam
mcbjam

Reputation: 7454

How to properly define a directives?

I see 2 syntax for define a directive in angular js.

The first way is :

angular.module("map-mcbjam", []);
angular.module("map-mcbjam", []).directive('map', function() { ...} )

The second way is :

angular.module("map-mcbjam", ['directives']);
angular.module('directives', []).directive('map', function() { ...} )

Can soemone know how to explain the differences between those 2 methods ?

Upvotes: 1

Views: 39

Answers (1)

Utopik
Utopik

Reputation: 3783

The second way allows you to share the directive between several modules :

angular.module("map-mcbjam", ['directives']);
angular.module("map2-mcbjam2", ['directives']);
angular.module("map3-mcbjam3", ['directives']);

angular.module('directives', []).directive('map', function() { ...} )

If you think your directive may be useful outside the module map-mcbjam, you should use the second way so that you can reuse it.

Upvotes: 2

Related Questions