Tuesday, 19 January 2016

How to bind a checkbox in angularjs with example

Syntax:<input type="checkbox" ng-model="expression" />
Checkbox in angularjs with example:


<div ng-controller="angularjsexampleCtlr" class="row">
    <div class="col-lg-12">
        <div class="col-lg-6">
            Get and Set Value form/in input
        </div>
        </div>
    <div class="col-lg-12">
        <div class="col-lg-6">
            <input type="checkbox" class="form-control" ng-model="value" />
        </div>
        <div class="col-lg-6">
            <button ng-click="myfun()">Show Value</button>
            <button ng-click="value=''">Reset</button>
        </div>
    </div>               
    </div>

o/p:     selectedValue= {{value}}

<script>
    angular.module('webapp', []).controller('angularjsexampleCtlr', function ($scope, $http) {
        $scope.myfun = function () {
            alert("Value : " + $scope.value);
        }
    });

</script>
Get and Set Value form/in input

1 comment :