我是整体编程的新手,这是我第一次尝试使用Angular,所以请在回答时考虑到这一点。有人建议我尝试使用Angular构建待办事项列表以了解有关java脚本的更多信息,并且当我点击添加任务按钮时,我仍然坚持如何获取我的数据(做项目)在我的表单上发布。表格重置,所以我知道按钮是"工作"但我的项目没有渲染。如果有人能帮助我,我会非常感激。
以下是我的代码的相关部分。提前感谢您的帮助。
HTML:
<form ng-submit= "addTodo()" class= "list-group-item">
<input type= "text" placeholder= "Add your task here" ng-model= "newTodo"/>
<select ng-model= "todoPriority">
<option value= "normal">Low</option>
<option value= "normal">Medium</option>
<option value= "normal">High</option>
</select>
<button ng-click= "addTodo()">Add Task to List</button>
</form>
app.js
(function(){
var app = angular.module('Todo-app', []);
app.controller('TodoCtrl', function($scope){
$scope.todos= [];
$scope.todoPriority= 'normal';
$scope.addTodo= function(){
var newTodo={
done: false,
text: $scope.todoText,
priority: $scope.todoPriority
};
$scope.todos.push(newTodo);
$scope.todoText = '';
$scope.todoPriority = 'normal';
};
$scope.getTotal= function(){
return $scope.todos.length;
};
$scope.removeTodo= function(start){
$scope.todos.splice(start, 1);
};
$scope.move= function(index, direction){
if (direction === 'up'){
if (index === 0){
return;
}
index = index -1;
}
if (direction === 'down'){
if (index === $scope.todos.length -1) {
return;
}
}
var todo= $scope.todos[index];
$scope.todos.splice(index+2,0, todo);
$scope.todos.splice(index, 1);
};
});
});