I am currently working on a ToDo App in Angular that adds "Todo's" as objects like so and also checks if the value is empty:
addTodo(newTodoLabel) {
var newTodo = {
label: newTodoLabel
};
if(newTodo.label == '') {
this.errorMessage = "Task description can't be empty";
} else {
this.todos.unshift(newTodo);
this.errorMessage = '';
this.infoMessage = "";
}
}
It will be added to this array:
todos = [
{
label: 'Add more task attributes'
}
];
And here is the HTML code as well:
<form #formCtrl="ngForm">
<div class="input-append">
<input class ="inputTask" maxlength="80" placeholder="Please enter a task description" type="text" class="form-control" #newTodo required />
<button class="buttonTask" (click)="addTodo(newTodo.value); newTodo.value=''" type="button" class="btn btn-primary form-control" >Add task</button>
Now my question is, how can I also check if the same property already exists in this array? (so that two tasks with the same name can't be added)