javascripthtmlangularjsattributesangularjs-ng-disabled

AngularJS - Submit button not disabling (im a newbie)


I know I'm doing something wrong, but here is the code:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<form>
    <input type="submit" ng-disabled="false" value="Not Disabled"/> <!-- Shouldn't be disabled -->
    <br>
    <input type="submit" ng-disabled="true" value="Disabled"/> <!-- Should be disabled -->
</form>

Why isn't the second submit button disabled? I searched online and I thought you could use ng-disabled to have a boolean as the disabled attribute.
Thanks.


Solution

  • The button will only be disabled if the expression evaluates to true and the parent element has the ng-app attribute.

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    
    <form>
        <input type="submit" ng-disabled="false" value="Not Disabled"/> <!-- Shouldn't be disabled -->
        <br>
        <div ng-app ng-init="disableBtn=true">
    <input type="submit" ng-disabled="disableBtn" value="Disabled"/> <!-- Should be disabled -->
    </div>
        
    </form>