-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToDoApp.html
More file actions
51 lines (42 loc) · 1.38 KB
/
Copy pathToDoApp.html
File metadata and controls
51 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body >
<div ng-app="todoApp" ng-controller="todoController">
<p>The list of to do tasks:</p>
<ul>
<li ng-repeat="x in toDoList">
{{ x }} <span ng-click="removeTask($index)">×</span>
</li>
</ul>
<p>Enter new Task: <input type="text" ng-model='taskName'/> <button ng-click="addTask()">Add</button> </p>
<span> {{ errortext }}</span>
</div>
<script>
var app = angular.module('todoApp', []).controller('todoController', function($scope) {
$scope.toDoList = ['Morning Meeting', 'Lunch Break','Complete AngularJS Course'];
//** add task
$scope.addTask = function() {
$scope.errortext = "";
if (!$scope.toDoList) {return;}
//** return if empty
if ($scope.taskName == "" || $scope.taskName == null) {
$scope.errortext = "Please enter task name...";
}
//** add task
else if ($scope.toDoList.indexOf($scope.taskName) == -1) {
$scope.toDoList.push($scope.taskName);
}
//** item already exists
else {
$scope.errortext = "Item is already added in the to do list..."
}
}
//** remove task
$scope.removeTask = function(x) {
$scope.toDoList.splice(x, 1)
}
});
</script>
</body>
</html>