【发布时间】:2015-06-02 13:55:46
【问题描述】:
我是 AngularJS 的新手 - 尝试构建一个漂亮的普通待办事项列表应用程序。 我不知道如何将输入框中的文本值推送到 'todos' 数组中。
这是我的代码。
HTML:
<body ng-controller="MainCtrl">
<div class="container">
<div class="main">
<p>Todo App</p>
<input ng-model="todoList" type="text" name="input" placeholder="Enter tasks here">
<button ng-click="addTodo()">Add</button>
<ul>
<li ng-repeat="todo in todos">
{{todo}
</li>
</ul>
</div>
</div>
</body>
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.todos = []
$scope.todoList = "";
$scope.addTodo = function(){
$scope.todos.push($scope.todoList)
}
$scope.clearAll = function(){
$scope.todos = []
}
});
提前致谢!
【问题讨论】:
-
有什么问题?您的代码工作正常! - JSFiddle 只是
}在{{ todo }中丢失了
标签: javascript arrays angularjs forms input