I am currently developing a task management application in Angular where tasks are added as objects and checked for empty values using the following code:
addTodo(newTaskLabel) {
var newTask = {
label: newTaskLabel
};
if(newTask.label == '') {
this.errorMessage = "Task description cannot be blank";
} else {
this.tasks.unshift(newTask);
this.errorMessage = '';
this.infoMessage = "";
}
}
The tasks are stored in this array:
tasks = [
{
label: 'Add more details to tasks'
}
];
Below is the accompanying HTML code:
<form #formCtrl="ngForm">
<div class="input-append">
<input class ="inputTask" maxlength="80" placeholder="Enter task description" type="text" class="form-control" #newTask required />
<button class="buttonTask" (click)="addTodo(newTask.value); newTask.value=''" type="button" class="btn btn-primary form-control" >Add Task</button>
My query now is, how can I implement a check to ensure that duplicate tasks with the same name are not added to the array?