Got error when user Http?

ForumGot error when user Http?
youxingzhi asked 1 year 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 1 year ago

Hi youxingzhi,

Add HTTP_PROVIDERS in bootstrap method defined in main.ts file

youxingzhi answered 1 year 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 1 year ago

That’s awesome!
You’re welcome. 🙂