I am trying to read a json github service and I am getting an error NullInjectorError: No provider for Http!
I already to add providers all over the code but it is not working I dont know what is causing the error but know where it is happening i need some who can help to understand what is causing this
import { Injectable } from '@angular/core';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule, Http, JsonpModule} from '@angular/http';
import { Observable} from 'rxjs';
import 'rxjs/add/operator/map';
@NgModule({
imports: [
BrowserModule,
HttpModule,
JsonpModule,
]
})
@Injectable({
providedIn:'root'
})
export class GithubService{
constructor(private http:Http){
}
getUser(){
const searchText ="js";
const url = "http://api.github.com/search/users?q="+searchText;
this.http.get(url).subscribe(
res=> {
const data=res.json();
console.log(data);
return data;
}
)
}
}
Error I am getting:
AppComponent.html:7 ERROR NullInjectorError: StaticInjectorError(AppModule)[GithubService -> Http]:
StaticInjectorError(Platform: core)[GithubService -> Http]:
NullInjectorError: No provider for Http!