I have two questions.
1.In addition, the empty value gets added to toDoList.
2.On trying to add a duplicate item, it doesn't add ok. But later it also doesn't add any item further.
There is also a default item added Sample. So I don't know how to do it.I also tried to solve the first problem by doing an empty check.But still is doesn't work.
I have not done anything with the description input so ignore it. This is my script.js, index.htm, and style.css file.
var app = angular.module('App', []);
app.controller('Ctrl', function($scope){
$scope.item = ["Sample"];
$scope.addTitle = function(){
$scope.item.push($scope.addMe);
};
$scope.removeItem = function(index){
$scope.item.splice(index,1);
};
});
body{
maring:0;
padding:0;
font-family: 'Inconsolata', monospace;
}
.container{
width: 100%;
height:100%;
display: flex;
align-items: center;
justify-content: center;
}
.form{
width:400px;
height: auto;
padding:20px;
}
.form input:nth-child(1){
padding:10px;
border:2px solid salmon;
font-family: 'Inconsolata', monospace;
}
.form input:nth-of-type(2){
padding:10px;
border:2px solid salmon;
font-family: 'Inconsolata', monospace;
width:400px;
}
.form button{
width:100px;
height:40px;
background-color: salmon;
border:1px solid salmon;
color:white;
font-family: 'Inconsolata', monospace;
}
.form button:hover{
color:salmon;
background-color: white;
cursor:pointer;
}
.itemList ul li{
list-style: none;
}
.itemList ul li a{
font-size: 0.8em;
color:red;
text-decoration: none;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
</head>
<body>
<div ng-app="App" class="container">
<div ng-controller="Ctrl" class="form">
<form>
<input type="text" name="title" placeholder="Title" ng-model="addMe" ng-required="true"><br><br>
<input type="text" name="description" placeholder="Description" ng-required="true"><br><br>
<button ng-click="addTitle()">Add</button>
<div class="itemList">
<ul ng-repeat="items in item">
<li>
{{items}}
<span ng-click="removeItem($index)"><br><a href="#">Remove</a></span>
</li>
</ul>
</div>
</form>
</div>
</div>
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
<script src="script.js" type="text/javascript"></script>