I have a variable selectedSubTopicId
and I have an array of subTopic objects: objectiveDetail.subTopics[]
. Each subTopic
object has a field subTopicId
I would like to use this to enable or disable and Add topic button. Can I use lodash in the ng-disabled to test this array and report true if any subTopic
object element of the array has a subTopicId
that is equal to the selectedSubTopicId
.
Here's a sample of the data that's in objectiveDetail. In this case there's just one element in the subTopics array.
{objectiveDetailId:285,
objectiveId:29,
number:1,
text:x,
subTopics:[{subTopicId:1,
number:1}]
}
Here is the code in my Angular Controller suggested by thefourtheye:
$scope.checkDuplicateSubTopicId = function (objectiveDetail, sSubTopic) {
if (_.some(objectiveDetail.subTopics, function(currentTopic) {
return _.contains(currentTopic, selectedSubTopicId);
})) {
return true;
} else {
return false;
}
}
My button with the click function not shown looks like this:
<button data-ng-disabled=checkDuplicateSubTopicId(objectiveDetail, subTopicId)>
Add Topic
</button>
The problem is that it's not quite working and the button does not show disabled.