Confused about Service vs Factory

后端 未结 20 2415
轻奢々
轻奢々 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:43

    All providers work the same way. The different methods service, factory, provider just let you accomplish the same thing in less code.

    P.S. There's also value and constant.

    Each special case down the chain starting with provider and ending with value has an added limitation. So to decide between them you have to ask yourself which let's you accomplish what you want with less code.

    Here is a picture that shows you what I mean:

    You can a breakdown and reference guide on the blog post I got this image from:

    http://www.simplygoodcode.com/2015/11/the-difference-between-service-provider-and-factory-in-angularjs/

提交回复
热议问题