December 21, 2015

How to disable click in AngularJS?




Here is a simple example for disable click in AngularJS,

<body ng-app="ngToggle">
    <div ng-controller="AppCtrl">
        <button ng-click="disableClick(1)">Disable ng-click</button>
    </div>
</body>

In JS:

angular.module('ngToggle', [])
    .controller('AppCtrl',['$scope', function($scope){
    $scope.flag = 0;
    $scope.disableClick = function(n) {
        if (n && n !== $scope.flag) {
            $scope.flag = n;
            alert("Clicked!");
        }
        return false;
    }
}]);




DEMO


Enjoy!

No comments:

Post a Comment

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...