Sunday, 22 November 2015

ng-readonly

What is ng-readonly:ng-readonly is used to make element (input ,select ,textarea) read only...
Description of ng-readonly:ng-readonly has priority 100. When given condition in ng-readonly is true ,targeted element become read only.Otherwise when condition is false targeted element has no effect...
Syntax of ng-readonly:

<element ng-readonly="expression">

</element>
or


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

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

Example 2:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr">
        <div>
            Angularjs Example of ng-readonly
            <input type="text" ng-readonly="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>

2 comments :