Angularjs Service vs Factory vs Provider

Source: Internet
Author: User

Angular provides us with three ways to create and register our own service.

1) Factory

2) Service

3) Provider

Tl;dr

1) When your ' re using a Factory you create an object, add properties to it, then return this same object. When you pass this service to your controller, those properties on the object would now is available in that controller T Hrough your factory.

2) When you ' re using Service, it's instantiated with the ' new ' keyword. Because of that, you'll add properties to ' this ' and the service'll return ' this '. When you pass the service to your controller, those properties on ' this ' 'll now is available on that controller Throug H your service.

3) Providers is the only service can pass into your. config () function. Use a provider if you want to provide module-wide the configuration for your service object before making it available.

NON TL;DR

1) Factory

Angularjs Service vs Factory vs Provider

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.