AngularJS Todo List App
Submitted by nurhodelta_17 on Monday, January 15, 2018 - 18:52.
Getting Started
I've used CDN for Bootstrap and Angular JS so you need internet connection for them to work.index.html
This is our index where we show our todo app list.- <!DOCTYPE html>
- <html lang="en" ng-app="app">
- <head>
- <meta charset="utf-8">
- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
- <style type="text/css">
- .div-list{
- background-color: #4CAF50;
- border: 1px solid #FFFFFF;
- color: #FFFFFF;
- padding: 10px 24px;
- cursor: pointer;
- width: 100%;
- display: block;
- margin-top:1px;
- }
- .div-list:not(:last-child) {
- border-bottom: none;
- }
- .div-list:hover {
- background-color: #FFFFFF;
- color: #4CAF50;
- border: 1px solid #4CAF50;
- }
- .mytask{
- margin-top:10px;
- }
- </style>
- </head>
- <body ng-controller="myController">
- <div class="container">
- <div class="row">
- <div class="col-sm-4 col-sm-offset-4">
- {{ counter }}
- <hr>
- <form ng-submit="addTask()">
- <input type="text" class="form-control" placeholder="New Task" ng-model="newtask">
- </form>
- <div class="mytask">
- <div class="div-list" ng-repeat="list in lists | filter:{ complete: 'false' }">
- <input type="checkbox" ng-model="list.Selected" ng-change="completeTask(list)"> {{ list.name }}
- </div>
- </div>
- <hr>
- <div class="mytask">
- <div class="div-list" ng-repeat="list in lists | filter:{ complete: 'true' }">
- {{ list.name }}
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
angular.js
And this is our angular js script.- var app = angular.module('app', []);
- app.controller('myController', function($scope, $filter){
- $scope.lists = [
- {
- taskid: 1,
- name: 'Learn Angular',
- complete: 'true'
- },
- {
- taskid: 2,
- name: 'Create Angular Apps',
- complete: 'false'
- },
- {
- taskid: 3,
- name: 'Submit Apps',
- complete: 'false'
- }
- ]
- $scope.countAllTask = function(){
- return $scope.lists.length;
- }
- $scope.addTask = function(){
- var obj = $scope.lists.length-1;
- if(obj < 0){
- var lastid = 1;
- }
- else{
- var lastid = $scope.lists[obj].taskid;
- }
- $scope.lists.push({
- taskid: lastid + 1,
- name: $scope.newtask,
- complete: 'false'
- });
- $scope.newtask = '';
- }
- $scope.deleteTask = function(list){
- var index = $scope.lists.indexOf(list);
- $scope.lists.splice(index,1);
- }
- $scope.completeTask = function(list){
- $scope.lists.find(function(v) {
- return v.taskid == list.taskid;
- }).complete = 'true';
- }
- $scope.deleteCompleted = function(){
- var completed = $filter('filter')($scope.lists, { complete: 'true' });
- angular.forEach(completed, function(list){
- var index = $scope.lists.indexOf(list);
- $scope.lists.splice(index,1);
- });
- }
- });
Add new comment
- 340 views