2

I have written a directive to achieve certain functionality. Now the scenario is that I need to add more varieties of that functionality. More varieties means the same functionality but there will be a few changes to the view/behavior.

How can I re-use the directive to achieve the above scenario. Do I have to create a separate directive for each variety?

After exploring from various sources, I have the following scenarios in my mind,

  • Create separate directive for each variety.
  • Group the common functions into a controller and use it for all the directives.
  • Do the directive specific changes in link function.

Is the above approach fine, or am I missing something here?

George Hilliard
  • 13,581
  • 5
  • 50
  • 88
Mathankumar
  • 567
  • 1
  • 8
  • 18
  • [This](http://stackoverflow.com/a/17005383/548403) answer might help you. – Varun Singh Feb 19 '15 at 07:59
  • have you used ng-click and ng-show on the same element.. they are two different directives, yet added to single element, provide different functionality – Naeem Shaikh Feb 19 '15 at 07:59
  • First of all, you would use a *service* to "group the common functions". To answer your question we need specific information about what exactly you mean with "varieties of that functionality". – DonJuwe Feb 19 '15 at 08:03

0 Answers0