javascript - Angular 2 No provider error -
i creating simple starter app play angular 2 , trying make todo service , inject him component , error:
no provider todoservice! (todolist -> todoservice)
todoservice.ts
export class todoservice { todos: array<object> constructor() { this.todos = []; } } app.ts
/// <reference path="typings/angular2/angular2.d.ts" /> import {component, view, bootstrap, for, if} 'angular2/angular2'; import {todoservice} './todoservice' @component({ selector: 'my-app' }) @view({ templateurl: 'app.html', directives: [for, if], injectables: [todoservice] }) class todolist { todos: array<object> constructor(t: todoservice) { this.todos = t.todos } addtodo(todo) { this.todos.push({ done:false, todo: todo.value }); } } bootstrap(todolist); what problem?
the injectables specified on @component not on @view
you have:
@component({ selector: 'my-app' }) @view({ templateurl: 'app.html', directives: [for, if], injectables: [todoservice] // moving line }) change to:
@component({ selector: 'my-app', injectables: [todoservice] // here }) @view({ templateurl: 'app.html', directives: [for, if] }) this allow di pick , inject component.
Comments
Post a Comment