0
我想了解Angular JS 2.当我尝试在https://angular.io/docs/js/latest/guide/user-input.html中提到的代码时,在输入文本并敲入回车键后,我得到一个插入到列表中的空白值。这里是ES5我想:Angular 2用户输入教程
//ES5
function TodoList() {
this.todos = ["Eat Breakfast", "Walk Dog", "Breathe"];
this.addTodo = function(todo) {
this.todos.push(todo.value);
};
this.doneTyping = function($event) {
if($event.which === 13) {
this.addTodo($event.target.value);
$event.target.value = null;
}
}
}
TodoList.annotations = [
new angular.ComponentAnnotation({
selector: "todo-list"
}),
new angular.ViewAnnotation({
template:
'<ul>' +
'<li *ng-for="#todo of todos">' +
'{{ todo }}' +
'</li>' +
'</ul>' +
'<input #textbox (keyup)="doneTyping($event)">' +
'<button (click)="addTodo(textbox.value)">Add Todo</button>',
directives: [angular.NgFor]
})
];
document.addEventListener("DOMContentLoaded", function() {
angular.bootstrap(TodoList);
});
这正是因为在Angular.io/docs提到,已经没有其他人看到同样的问题?文档中是否有错误?