I'm trying to access a JSON
feed but after making the changes from the documentation I get the following error
"Cannot find name 'HttpClient'"
I've looked over the tutorial a few times but I'm struggling to find why I get this error.
My component where I perform the Http request.
rooms.parent.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
/.../
})
export class RoomParentComponent implements OnInit {
results: string[];
// Inject HttpClient into your component or service.
constructor(private http: HttpClient) {}
ngOnInit(): void {
// Make the HTTP request:
this.http.get(/.../).subscribe(data => {
this.results = data;
});
}
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {HttpClientModule} from '@angular/common/http';
import { AppComponent } from './app.component';
import { RoomParentComponent } from './rooms.parent.component';
@NgModule({
declarations: [
AppComponent,
RoomParentComponent
],
imports: [
BrowserModule,
HttpClientModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
How do I resolve the above error and inject the HttpClient into the constructor?
Edit: My Angular version is 4.3.2