Confused about Service vs Factory

后端 未结 20 2758
轻奢々
轻奢々 2020-11-22 08:49

As I understand it, when inside a factory I return an object that gets injected into a controller. When inside a service I am dealing with the object using this

20条回答
  •  执念已碎
    2020-11-22 09:41

    Very simply:

    .service - registered function will be invoked as a constructor (aka 'newed')

    .factory - registered function will be invoked as a simple function

    Both get invoked once resulting in a singleton object that gets injected into other components of your app.

提交回复
热议问题