Error: No provider for Http!

I made this provider for my app.

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class UserProvider {

  Theme: {color: string};
  info: Info;
  
  constructor(public http: Http) {
    console.log('Hello UserProvider Provider');
    this.Theme.color = "primary";
    this.info.name = "test";
    this.info.dob = "xx/xx/xxxx";
    this.info.tob = "XX:XX";
    this.info.email = "test.123@test.com";
    this.info.city = "SomeCity";
  }  

  getInfo() {
    return this.info;
  }

  getTheme() {
    return this.Theme;
  }

}

interface Info {
  name: string;
  dob: string;
  tob: string;
  email: string;
  city: string;
}

I am trying to use it here like this:

  constructor(public navCtrl: NavController, public navParams: NavParams, public user: UserProvider) {
    this.Theme = this.user.getTheme();
  }

The app doesn’t load and shows this error:
https://gyazo.com/60cdf39ba455d4424f4cae0ee7668fae

I tried adding it in the providers list in app.module.ts but then it showed no provider for backend error.
What do I do? Please thanks.

Regards!

1 Like

Hi,

Please see this thread: Uncaught (in promise): Error: No provider for Http

Could you please confirm that you import HttpModule in app.module.ts?

1 Like

You search the forums for your error message and find a bunch of threads like this one that tell you to take Http out of your app module’s providers.

No I didn’t but now I did and it worked! :slight_smile:
Thank you but could you please explain why I need to do that?

Thanks!! It works for me.