So I'm working on this web application. I have a list of categories, where if an item on the list is not checked, the "Save"and "Publish"buttons would be disabled. I understand ng-disabled = !(ng-model name)would do just that, but each time, I load the page, the buttons are disabled, but do not get enabled when I check an item on the list.
<a ng-if="status() < 2" href="#" data-ng-click="publish(true)" class="btn btn-sm btn-block btn-success" ng-disabled="!cat.IsSelected">{{lbl.publish}}</a>
<a ng-if="status() == 2" href="#" data-ng-click="save()" class="btn btn-sm btn-block btn-primary" id="check_box" ng-disabled="!cat.IsSelected">
{{lbl.save}}
</a>
<span ng-if="status() < 2">
<a href="#" ng-click="save()" class="btn btn-sm btn-block btn-primary" id="check_box" ng-disabled="!cat.IsSelected">
{{lbl.save}}
</a>
</span>
<ul class="categories-list">
<li ng-repeat="cat in lookups.CategoryList">
<label><input type="checkbox" id="cat-{{cat.OptionValue}}" data-ng-model="cat.IsSelected"/> {{cat.OptionName}}</label>
</li>
<li ng-if="lookups.CategoryList.length == 0" class="item-empty">{{lbl.empty}}</li>
</ul>
JS Code:
$scope.post.Categories = [];
if ($scope.lookups.CategoryList != null) {
for (var i = 0; i < $scope.lookups.CategoryList.length; i++) {
var cat = $scope.lookups.CategoryList[i];
if (cat.IsSelected) {
var catAdd = { "IsChecked": false, "Id": cat.OptionValue, "Title": cat.OptionName };
$scope.post.Categories.push(catAdd);
}
}
}
ng-disabled(disableattribute) doesn't work on anchor tag..<a>element. Perhaps the logic insave()can check your condition and simply not perform its logic?