Today we’ll be creating a simple todo list, which you’ll be able to modify to meet your own needs. Before beginning, I highly suggest reading over this article, which details how RethinkDB differs from some of the other NoSQL databases. Join 25 million people and teams that organize, plan, and collaborate on tasks and projects with Todoist. 'The best to-do list' by The Verge.
Download Simple Todo: Quick and Easy and enjoy it on your iPhone, iPad, and iPod touch. Simple Todo app with two categories. One category is for tasks that need to be tackled immediately and the other one is for tasks that can wait. ## ‘Do!’ is the easiest way to use ‘To Do List app’ in the iOS ## ## No more wasting time on making the list itself! ##. You don't need to study this app. Just follow your instinct!. No more stiff basic fonts!. A realistic ball point pen & paper sound effect!. Don’t waste any more time in maki. Simple TODO list. After loading angular.min.js we create an Angular JS module called todoApp and a controller called todoController.Inside the controller we set up an empty array called tasks that will hold the todo list.
PrevNext
Trailing closely the Hello world,the Echo, and the simple calculatorexamples, creating a TODO list is one of the rite of passage entering the world of whateverlanguage or environment. Let's see how to implement a TODO using AngularJS.
Simple TODO list
After loading angular.min.js we create an Angular JS module called todoApp anda controller called todoController. Inside the controller we set up an empty arraycalled tasks that will hold the todo list.We make it an attribute of the current $scope in order to make it accessible form the HTML.
We also declare a function called add (also an attribute of the $scope) that takes thevalue of title (we'll later see this is the name of the input box), and appends itto the list of tasks using push. That's all the JavaScript code we need for a simple TODO list.
Simple Todo List App
In the HTML part we have a div element that defined the area of theAngularJS Application ng-app and the Angular JS controller ng-controller.
Inside the controller in the HTML we have two parts. The first part is an input elementconnected to the $scope.title attribute using ng-model and a button that usesng-click to launch the $scope.add method when the button is clicked.
The second part uses the ng-repeat directive to iterate over the elements of the $scope.tasksarray and display them one-by-one as list items.
Simple Todoroki
examples/angular/todo1.html Try!
Submit input box on pressing ENTER
It is a bit cumbersome that for every additional item we need to click on the button.It would be much better if we could just press ENTER. In order to do that we had to wrapthe input element in a form and in the form add an ng-submitdirective calling the $scope.add function. At the same time, in order to eliminateduplicate calling of the $scope.add function. Bitmedic® pro antivirus 3 1.
Duplicate values in ng-repeat
If yo have tried the above example, you might have noticed that adding the same element twicewill crash the application. The reason is that by default the ng-repeat directiveassumes unique values in an array. I am not sure if having the same value in a TODO listis actually desirable, but for now I'd like to be able to allow the user to enter the same valuetwice. To do so we can tell ng-repeat to use the $index of the array for trackingvalues like this:
Deleting an element from the TODO list
While for most of us the reality is that we have an ever growing TODO list, but sometimewe get lucky and manage to finish an item. (Or maybe it just gets cancelled.) We would liketo have a way to remove an element. For that we are going to add a button next to each item,and clicking on that button will remove the specific element from the array of tasks.
Adding the button is simple:
The appropriate delete function made me scratch my head a bit, but finally Igot it:
When running the delete function this contains an attribute called $index thatseems to indicated the index in the current list. We can use that to locate the element in thetasks array. Using the plain JavaScript splice function we remove one element fromthe array that immediately updates the list displayed on the HTML page.
examples/angular/todo2.html Try!
Published on 2015-08-07
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.