Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TODO with AngularJS (ENTER to submit and delete item)

  • ng-submit
<script src="angular.min.js"></script>
<script src="todo2.js"></script>
<div ng-app="todoApp" ng-controller="todoController">
    <form ng-submit="add()">
    <input ng-model="title"><button>Add</button>
    </form>
    <ul>
        <li ng-repeat="t in tasks track by $index">{{ t }}
             <button ng-click="delete()">x</button></li>
    </ul>
</div>
angular.module('todoApp', [])
    .controller('todoController', ['$scope', function($scope) {
        $scope.tasks = [];
        $scope.add = function() {
            $scope.tasks.push($scope.title);
        }
        $scope.delete = function() {
            $scope.tasks.splice(this.$index, 1);
        }
    }]);