angularjsbuttonangularjs-ng-disabled

Disable Button if nothing is selected at the dropdown


The button should be disabeled, when nothing is selected at the dropdown. How can I achieve this?

<select size='1' id="action" ng-model="ak.action">
    <option value='1'>RED</option>
    <option value='2'>BLUE</option>
</select>

<div>
    <button type="button" ng-Click="ak.save()" >SAVE</button>
</div>


Solution

  • Try using ng-disabled="!ak.action || ak.action.length == 0" on the button. Although the select will always have a selected item in your case...

    <select size='1' id="action" ng-model="ak.action">
            <option value='1'>RED</option>
            <option value='2'>BLUE</option>
    </select>
    
    <div>
        <button ng-disabled="!ak.action || ak.action.length == 0" type="button" ng-click="ak.save()" >SAVE</button>
    </div>