I have a drop down that adds items on a page that are binded to a $scope. I basically want to make sure I don't add doubles to the array so my idea is to ng-hide the option if it already exists in the array. I don't know if it's possible to do something like this because the ng-options is inside the select so I dont know if i can append an ng-hide to them in the first place.
Regardless, if it is possible, I would like to hide the option if it's id already exists in a scope.
I was thinking you would just loop through each and check, here is my attempt
$scope.checkifExist = function () {
var ifExist = false;
angular.forEach($scope.promptsPlease, function (data) {
if (data.id == $scope.promptsPlease.id){
ifExist = true;
}
});
return ifExist;
};
and so the select in the controller looks like
<select ng-model="fadingSelected" ng-options="type.name for type in fadingTypes track by type.id" ng-hide="checkIfExist()">
</select>
I don't know if this is even possible, and I think I might just be approaching this all wrong. The idea is just so I cannot add the same one twice to the array that's binded to the scope. It doesn't necessarily have to ng-hide, it would just be nice. Any help would be appreciated! Thanks for reading.