I am learning to use Angular 2 and have reached a point here I am stuck with the error below. This only appears since adding the httpClientModule and trying to make a http get request from a components ngInit. The app is using angular 4.3.4.
Can't resolve all parameters for BlogComponent: (?).
contents of app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { BlogComponent } from './blog.component';
import { HomeComponent } from './home.component';
import { appRoutes } from './routes'
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot(appRoutes)
],
declarations: [
AppComponent,
BlogComponent,
HomeComponent
],
bootstrap: [AppComponent],
})
export class AppModule { }
contents of the blog component ts file which is throwing the error
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'test-blog',
template: '<h1>Blog page :)</h1>',
})
export class BlogComponent implements OnInit{
results: string[];
constructor(private http: HttpClient) {}
ngOnInit(): void {
// Make the HTTP request:
this.http.get('/api/blog/all').subscribe(data => {
// Read the result field from the JSON response.
this.results = data['results'];
});
}
}