python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
validate a check box in ng click angularjs

Validate AngularJs checkbox on ng click

Hello everyone,  I am going to share the code-sample to validate a check-box when click on any submit form button in angularjs apps.
In the given angular check-box, by default ng-model value is false and after checked to check-box get the ng-model value is true. The behalf of the value true/false we are display the error messages on the form.
The example detail as given below.
The AngularJs code-sample

var app = angular.module('validateApp', []);
app.controller('validateController', function ($scope) {
    $scope.checkoutTerms = false;//Default

    //Click function
    $scope.myClick = function (checkoutTerms) {
        alert('checkbox is validate : ' + checkoutTerms);
    };
});
The HTML code-sample

<div ng-app="validateApp">
    <div ng-controller="validateController">
        <h1>Validate checkbox on ng click</h1>
        <input type="checkbox" ng-model="checkoutTerms">
        <button ng-click="myClick(checkoutTerms)">Click</button>
    </div>
</div>
The Full live demo(HTML + AngularJs) code-sample as given below.

<!doctype html>
<html>
<head>
    <script src="http://code.angularjs.org/1.2.3/angular.min.js"></script>
    <script>
        var app = angular.module('validateApp', []);
        app.controller('validateController', function ($scope) {
            $scope.checkoutTerms = false;//Default

            //Click function
            $scope.myClick = function (checkoutTerms) {
                alert('checkbox is validate : ' + checkoutTerms);
            };
        });
    </script>
</head>
<body ng-app="validateApp">
    <div ng-controller="validateController">
        <h1>Validate checkbox on ng click</h1>
        <input type="checkbox" ng-model="checkoutTerms">
        <button ng-click="myClick(checkoutTerms)">Click</button>
    </div>
</body>
</html>
The output: to go live demo http://embed.plnkr.co/HuaZRa/preview



ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions