I'm trying to pass two text field values into and array using AngularJS, but I also want to check if the first value being passed already exists in the array. If it does I do not want it added again, if it doesn't exist then add the values. I can get it to add the values but I'm getting stuck trying to check if the last name value exists already in the array. I had found some examples I tried to follow but I cant seem to get them to work. Thanks for any help!
<div class="panel-body">
<div ng-controller="TodoCtrl">
<ul>
<li li ng-repeat="todo in todos">
{{todo.text}}, {{todo.name}}
</li>
</ul>
<form class="form-horizontal">
<input type="text" ng-model="formTodoLast" ng-model-instant>
<input type="text" ng-model="formTodoFirst" ng-model-instant>
<button class="btn" ng-click="addTodo()"><i class="icon-plus"></i>Add</button>
</div>
</div>
todo.js
function TodoCtrl($scope) {
$scope.todos = [];
$scope.addTodo = function () {
if($scope.todos.indexOf(text:$scope.formTodoLast) == -1) {
$scope.todos.push({text:$scope.formTodoLast, name:$scope.formTodoFirst});
$scope.formTodoText = ' ';
$scope.formTodoName = ' ';
}
}
}