This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14065|Reply: 2

[ionic] ionic3 provider

[Copy link]
Posted on 6/21/2018 2:13:56 PM | | |
provider, also called service. The former is the name of ionic, and the latter is the name of ng.

When a duplicate requires a method in a class, it can be encapsulated as a service class for reuse, such as http.

Import the decorator first, and then decorate it with the decorator so that the class can be injected into other classes as a provider to use:


Of course, we don't need to create the above manually, enter the command:
ionic g provider http
It will help you create it in the providers folder and import it in the app.module.

Use:
Import in the page you want to use:

Then, inject into the constructor to create an instance:

This way, we can use the method in HttpProvider:

this.httpProvider.myAlert()





Previous:ionic3 page lifecycle events (hooks)
Next:Newcomers register, please pay attention
Posted on 6/25/2018 10:00:02 AM |
In what scenarios is this applied?
 Landlord| Posted on 6/25/2018 2:52:30 PM |
Pearl Posted on 2018-6-25 10:00
In what scenarios is this applied?

App development
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com