In the angular service, which is the most basic implementation? (Provider)

Source: Internet
Author: User

I just saw this section today.

Excerpt, and later, after the actual operation is complete, all the code will be

Sometimes, it might is interesting to create configurable services. They is called providers, and despite being more complex to create, they can configured before
Being available to is injected inside other components.
While the factory works by returning a object and the service with the constructor function, the provider relies on the $ Get function to expose its
Behavior. This is the everything returned by this function becomes available through the dependency injection.
In the following code, we refactored our service to being implemented by a provider. Inside the $get function, the Calculateticket method is being returned and would be
Accessible externally.

Parking.provider ("Parkingservice",function(parkingconfig) {var_parkingrate =parkingconfig.parkingrate;var_calculateticket =function(car) {varDeparthour =NewDate (). getHours ();varEntrancehour =car.entrance.getHours ();varParkingperiod =Departhour–entrancehour;varParkingprice = Parkingperiod *_parkingrate;return{period:parkingperiod,price:parkingprice};}; This. setparkingrate =function(rate) {_parkingrate=Rate ;};This . $get = function () {return {calculateticket: _calculateticket};};});

In the angular service, which is the most basic implementation? (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.