I recently completed a tutorial on Angular and Rails which I found here, but I am encountering difficulties in implementing it successfully.
Currently, I am working with Angular version 4.2.4.
[Error] ERROR
Error: No provider for Http!
injectionError — core.es5.js:1169
...
View_AppComponent_Host_0 (AppComponent_Host.ngfactory.js:4)
...
It seems that there have been some updates in Angular since the tutorial was published, such as the replacement of the following code:
import { Http } from '@angular/http';
with this:
import { HttpModule } from '@angular/http';
I attempted to make this change by adding HttpModule
to the imports
array in `app.module.ts.`
app.component.ts
import { Component } from '@angular/core';
import { HttpModule } from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
books;
constructor(private http: Http) {
http.get('http://localhost:3000/books.json')
.subscribe(res => this.books = res.json());
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
If anyone has any suggestions or insights to offer, I would greatly appreciate it.
Thank you!