I am developing an app in AngularJS.
1. I would like to know how can I disable a button if the input value typed by the user is not a item of the uib-typeahead list (in this case the Array items)? And enable it when it is a item of the array?
2. And also, how can I disable the same button when the user tries to add a item of the Array items through the Add button that was already added? The items are saved in the Array addedItems.
This is the input and button in HTML:
<input type="text" ng-model="search1" uib-typeahead="item for item in items
| filter:$viewValue | limitTo:10"/>
<button type="submit" class="btn btn-success" ng-click="action()"
ng-disabled="(!search1)">Add</button>
This is a sample of the items Array structure:
var items = ["admin1", "admin2", "admin3", "admin4", "admin5"];
The action() function is defined in the controller in JavaScript:
$scope.items = ["admin1", "admin2", "admin3", "admin4", "admin5"];
$scope.search1 = undefined;
$scope.addedItems = [];
$scope.action = function() {
$scope.addedItems.push($scope.search1);
}
Thank you *