Angular JS Magazine

vineri, 29 august 2014

Disable a Button Using ng-disabled

This tip shows how to disable a button using ng-disabled directive:

<!DOCTYPE html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="../angular/angular.min.js"></script>
    <link href="../bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../bootstrap/css/bootstrap-theme.css" rel="stylesheet" />
        angular.module("atpModule", [])
                .controller("atpCtrl", function ($scope) {
                    $scope.handleEvent = function (e) {
                        $ = true;
<div ng-app="atpModule" ng-controller="atpCtrl">

    <div id="atpPanel" class="panel">
        <h3 class="panel-header">Click button 'One' to disable button 'Two'</h3>
        <button class="btn btn-success" ng-click="handleEvent($event)">One</button>
        <button class="btn btn-success" ng-disabled="data">Two</button>

First run:
 After pressing button "One":