我有一个DOM按钮,当没有选择用户时它被禁用(加载时它被设置为false)但是,我还需要在数组为空时禁用此按钮。例如,我有一组组,当添加了所有组后,我想要禁用添加按钮。
<div>
<label for="entityAvailable">Available Groups</label>
<select id="entityAvailable" multiple
ng-model="selectedAvailableGroups"
ng-options="g.name for g in availableGroups | orderBy:'name'">
</select>
</div>
<div id="moveButtons" >
<button type="button" ng-disabled="!selectedUser || availableGroups == []" ng-click="addUserToGroup()">Add User</button>
<button type="button" ng-disabled="!selectedUser" ng-click="removeUserFromGroup()">Remove</button>
</div>
<div>
<label for="entityAssigned">Assigned Groups</label>
<select id="entityAssigned" multiple
ng-model="selectedAssignedGroups"
ng-options="g.name for g in assignedGroups | orderBy:'name'">
</select>
</div>
答案 0 :(得分:2)
你可以做到
ng-disabled="!selectedUser || availableGroups.length == 0"