How to create a new provider? IONIC 3 Angular 4

Here we will learn how to create a new provider or add new services in ionic 3 applications.
This tutorial will help you to learn basics of provider.

Step (1)

write this command in your cli.

$ ionic g provider auth

it will generate these folders and file in your project.

[adToAppearHere]

Step (2).

open “app.module.ts” and add following lines

import { HttpClientModule } from ‘@angular/common/http’;
.
.
.
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpClientModule
],
.
.
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
AuthProvider
]
And its done.
Note : if you get the following errors then above solution will work like charm.
error 1———————–>
Uncaught (in promise): Error: StaticInjectorError[HttpClient]:
StaticInjectorError[HttpClient]:
NullInjectorError: No provider for HttpClient!
error 2———————->
Error: StaticInjectorError[AuthProvider]:
StaticInjectorError[AuthProvider]:
NullInjectorError: No provider for AuthProvider!
Enjoy….. 🙂
——————-End Of tutorial—————–
Knowledge booster
  • what is a provider – it is a ready to plug in service which can be used in application just by importing it to page.
  • why we use providers –  we use providers to consume REST services and to provide some data to application using some external sources.
  • how to create ionic project – follow this link

Author Profile

PREM KUMAR
PREM KUMAR
Tech Lover , Open Src Dev , Dotnet Core, Ionic, Xamarin, Node, Angular2, Python, Opencv, AI, ML, Robotics, SignalR, Iot, Love Music, Cooking, Girls, Innovation.
Like
Like Love Haha Wow Sad Angry
3

One thought on “How to create a new provider? IONIC 3 Angular 4

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Enable Notifications.    Ok No thanks