search

Home  >  Q&A  >  body text

angular.js - What are the differences and applicable scenarios between service, factory and controller in angularJs?

New to angularJs
What are the differences between service, factory, and controller in angularJs, and where do they apply?

漂亮男人漂亮男人2780 days ago738

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-15 16:55:20

    Controller focuses on business scenarios, that is, serving specific scenarios, so do not reuse controllers. It is recommended to divide controllers in a small range and use parent-child scopes to meet business scenarios.

    factory provides some public methods and functions, it is recommended to abstract and reuse factory.

    Service is similar to factory. It will be instantiated and can save data. It is used as a communication tool between controllers and is recommended for reuse.

    reply
    0
  • Cancelreply