Following a tutorial, I am trying to inject a service in 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);
}
}
When calling TodoService, I get 'constructor implementation is missing'
My Service:
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)));
}
}
What do I need to do to clear the error, since my TodoService is using Http?
constructor(private _todo: TodoService);withconstructor(private _todo: TodoService) { }.