简体   繁体   中英

What are the purposes/advantages of designing different 'services' in Angular.js

I am a beginner of Angular.js.

When I read some brief examples on services (factory, provider, service, value, constant, etc), I found that for simple examples many of them are able to return exact same data, with only slight difference in implementation.

I would like to know if there is any advantages to design various forms of services?

Yes I totally agree to steppe fox...

I use services for the normal Model part of the MVC Paradigm because they are very easy to create and inject wherever and whenever you need them...

My own usage is... Controller for any modification / event handling of the view (html, two way data binding) Service for any business logic purpose that doest stuff like big calculations, modify data, etc... Factory for any connection purpose, like connecting to a Backend, or Loading Data from DB, or so one...

For me I don't see a bigger need to decide between a service or a factory...

I also Googled a lot, because I wondered that there is no difference... But I have not found any information about big differences...

Value and Constant are interesting for stuff you globally need in your app... Like the main URL stub to your backend or something like this...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM