2

My question is basically on handling directive event listeners.

I have tiles in my project list screen and each tile will have let's say 6-7 click handlers.

I am creating tile as a directive. Also my project list screen can have n no. of tiles.

My question is whether it's good to have each tile event listeners in directive or controller? Because if i keep event listeners in my directive then let's assume i have 50 tiles in a page then 50*6=300 listeners will be there for that page. Kindly explain me.

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
Nandish
  • 125
  • 2
  • 11

1 Answers1

0

I suppose that perfomance with 50 handlers in each directive and perfomance with 6 handlers in controller is quite similar. But in first we use little more browser memory.

It will be the phylosophic question - "where can i keep my handlers?"

If you have over 5000 components then it will be more better to keep handlers in controller. But if you know that you have only one component on screen than you can keep handlers in directive.

My choice is to keep my directives very dummy. It means that directives have no handlers inside and have all handler`s stuff in angular controller.

k.makarov
  • 854
  • 1
  • 12
  • 28