mvc小案例:

代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Template • TodoMVC</title>
<!-- <link rel="stylesheet" href="css/base.css"> -->
<link rel="stylesheet" href="css/index.css">
<!-- CSS overrides - remove if you don't need it -->
<link rel="stylesheet" href="css/app.css">
</head>
<body ng-app="Todos">
<section class="todoapp" ng-controller="TodoController">
<header class="header">
<h1>todos</h1>
<form ng-submit="add()">
<!-- 用户输入点 -->
<input class="new-todo" placeholder="What needs to be done?" ng-model="text" autofocus>
</form>
</header>
<section class="main">
<input class="toggle-all" type="checkbox">
<label for="toggle-all">Mark all as complete</label>
<ul class="todo-list">
<li ng-repeat="(key,todo) in todos">
<div class="view">
<input type="checkbox" class="toggle" ng-click="done(key)" >
<label>{{todo.text}}</label>
<button class="destroy" ng-click="delete(todos,key)" ></button>
</div>
<input class="edit" value="Create a TodoMVC template">
</li>
<li><h5>已完成</h5></li>
<li class="completed" ng-repeat="todo in doneTodos">
<div class="view">
<input class="toggle" type="checkbox" ng-checked="todo.flag" >
<label>{{todo.text}}</label>
<button class="destroy" ng-click="delete(doneTodos,key)"></button>
</div>
<input class="edit" value="Rule the web">
</li>
</ul>
</section>
<footer class="footer">
<span class="todo-count"><strong></strong> {{todos.length}} item left</span>
<button class="clear-completed">Clear completed</button>
</footer>
</section>
<footer class="info">
<p>Double-click to edit a todo</p>
<p>Template by <a href="http://sindresorhus.com">Sindre Sorhus</a></p>
<p>Created by <a href="http://todomvc.com">you</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
</body>
<script src="../../js/angular.min.js"></script>
<script>
angular.module('Todos',[]).controller('TodoController',['$scope',function($scope){
// 定义一个数组存储用户输入的数据
$scope.todos = [];
$scope.doneTodos = [];
$scope.add = function(){
$scope.todos.push({text:$scope.text,flag:false});
$scope.text = '';
}
$scope.done = function(key){
var todo = $scope.todos.splice(key,1)[0];
todo.flag = true;
$scope.doneTodos.push(todo);
// console.log($scope.todos.splice(key,1));
}
$scope.delete = function(todos,key){
todos.splice(key,1);
}
}]);
</script>
</html>









