ionic tutorial
ionic tutorial
in , , ,

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
Hey Its..! Tech Lover , Ionic, Angular, Typescript, Dotnet Core, Node, Like Opencv, AI, ML, Robotics, Iot, Love Music, Cooking, Girls, Innovation

One Comment

Leave a Reply

    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.

    What do you think?

    400 Points
    Upvote Downvote
    405 method not allowed - pkworlz

    405 Method Not Allowed error with PUT or DELETE Request on ASP.Net application

    Add New Code Snippet In Visual Studio 2017