-1

Both of them look like simple functions with the controllers having a scope with them. What exactly is the difference between them?

me_digvijay
  • 5,374
  • 9
  • 46
  • 83

2 Answers2

2

Controllers and filters may look like simple function to you but they are not the same.

Controllers are used mainly to control Angular scope object which is used to control views whereas filters are used to filter out some elements(also in view) based on user's choice. There are a lot of built in filters already and you can always create a filter on your own. You should never use Controllers for filtering, use filters instead.

Their names themselves provide the difference b/w them. Read Controller Documentaion and Filter documentation to know more.

Aniket Sinha
  • 6,001
  • 6
  • 37
  • 50
2

Controllers facilitate the interaction between the view, model and user, as per MVC.

Filters, on the other hand, modify data that is passed to them and output the result. They can be viewed as a pipeline that data passes through on the way from the model to the view.

Neither are "simple functions" but should be rather viewed as objects that serve specific purposes.

Jens Neubauer
  • 1,090
  • 1
  • 13
  • 24