at a glance...
Module(s)
config
Route
UI
View
Directives
Expressions
Filters
$scope
Logic/Data
Controller
Factory(ies)
Service(s)
<div>
<h1>Todo List</h1>
<ul id="todoList"></ul>
<h1>Add New Todo Item</h1>
<input type="text" id="newTodo" />
<br />
<span>You are entering:
<span id="newTodoItemValue"></span>
</span>
<br />
<button id="addTodo">Add</button>
</div>
var todos = [];
var newTodoItemValue;
$("#addTodo").on("click", function(e){
newTodoItemValue = $("#newTodo").val();
todos.push(newTodoItemValue);
$("#newTodo").val('');
refreshList();
$("#newTodoItemValue").html('');
});
$("#newTodo").keyup(function() {
newTodoItemValue = $(this).val();
$("#newTodoItemValue").html(newTodoItemValue);
});
function refreshList(){
$("#todoList").html('');
$.each(todos, function( i, val ) {
$("#todoList").append('<li>' + val + '</li>');
});
};
index.html
app.js
<div ng-controller="TodoCtrl">
<h1>Todo List</h1>
<ul>
<li ng-repeat="todo in todos">
<span>{{todo}}</span>
</li>
</ul>
<h1>Add New Todo Item</h1>
<input type="text" ng-model="newTodo"/>
<button ng-click="addTodo(newTodo)">Add</button>
</div>
angular.module('todoApp', [])
.controller('TodoCtrl', function($scope){
$scope.todos = [];
$scope.addTodo = function(todoItem){
$scope.todos.push(todoItem);
$scope.newTodo = "";
}
});
index.html
app.js