Currently following a tutorial, I am in the process of injecting a service into my component:
import { Component } from '@angular/core';
import { TodoService } from './todos.service';
import { ITodo } from './todo';
import { Http , Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Component({
selector: 'my-app',
templateUrl: `app/app.component.html`,
providers: [TodoService]
})
export class AppComponent
{
itodos: ITodo[];
appTitle: string = 'To Do App';
constructor(private _todo: TodoService);
ngOnInit() : void {
this._todo.gettodos()
.subscribe(itodos => this.itodos = itodos);
}
}
Issue encountered when calling TodoService: 'constructor implementation is missing'
The Service I am using:
import { Injectable } from '@angular/core';
import { Http , Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import { ITodo } from './todo';
@Injectable()
export class TodoService {
private _todoUrl='app/todos.json';
constructor(private _http: Http){}
gettodos(): Observable<ITodo[]> {
return this._http.get(this._todoUrl)
.map((response: Response) => <ITodo[]> response.json())
.do(data => console.log(JSON.stringify(data)));
}
}
To resolve the error due to Http being used by my TodoService, what steps should I take?