我正在创建简单的入门应用程序来使用 angular 2,我正在尝试创建一个 todo 服务并将他注入我的组件,我收到了这个错误:
TodoService 没有提供者!(TodoList -> TodoService)
TodoService.ts
export class TodoService {
todos: Array<Object>
constructor() {
this.todos = [];
}
}
应用程序.ts
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap, For, If} from 'angular2/angular2';
import {TodoService} from './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);
问题是什么?