ng-selected

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

</element>
or

<select>
    <option value="1" ng-selected="expression">One</option>
    <option value="2">Two</option>

</select>
How to Use ng-selected/ng-selected Example::
Example 1:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr" ng-init="flag=true">
        <div>
            Angularjs Example of ng-selected
            <select>
                <option value="1" ng-selected="flag">One</option>
                <option value="2">Two</option>
            </select>

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

Example 2:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr">
        <div>
            Angularjs Example of ng-selected
            <select>
                <option value="1" ng-selected="flag">One</option>
                <option value="2" >Two</option>
            </select>
            <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