Got error when user Http?

ForumGot error when user Http?
youxingzhi asked 6 years ago
Start your code here
import {Http} from '@angular/http';

selector: 'test-cmp',
templateUrl: 'test.html',
styleUrls: ['test.css'],

export class TestComponent {
public mobiles;
constructor(public http:Http) {
this.http.get('test.json').subscribe(res=> this.mobiles =res.json());
The error is:
No provider for http
2 Answers
Best Answer
admin Staff answered 6 years ago

Hi youxingzhi,

Add HTTP_PROVIDERS in bootstrap method defined in main.ts file

youxingzhi answered 6 years ago

Yes, I did as you say:
import { HTTP_PROVIDERS } from ‘@angular/http’;
bootstrap(AppComponent, [
provide(APP_BASE_HREF, { useValue: ‘<%= APP_BASE %>’ })
I have resolved it. Thank you!

admin Staff replied 6 years ago

That’s awesome!
You’re welcome. 🙂