Sunday, 22 November 2015

ng-checked

What is ng-checked:ng-checked is used to checked/unchecked status off radio/checkbox ..
Description of ng-checked:ng-checked has priority 100. When ng-checked has a true condition it makes status checked in other hand when given condition is false status of input (type: radio, checkbox ) become unchecked..
Syntax of ng-checked:
<element ng-checked="expression">

</element>
or


<input type="checkbox" ng-checked="expression" />
How to Use ng-checked/ng-checked Example::
 Example 1:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr" ng-init="flag=true">
        <div>
            Angularjs Example of ng-checked
            <input type="checkbox" ng-checked="flag" />

        </div>
    </div>
</div>

Example 2:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr">
        <div>
            Angularjs Example of ng-checked
            <input type="checkbox" ng-checked="flag" />
            <input type="button" ng-click="myfun()" />
        </div>
    </div>
</div>

<script>
    angular.module('webapp', []).controller('angularjsexampleCtlr', function ($scope, $http) {
        $scope.myfun = function () {
            if ($scope.flag == false || $scope.flag == undefined)
                $scope.flag = true;
            else
                $scope.flag = false;
        }
    });
</script>

No comments :

Post a comment