Friday, 13 November 2015

ng-keypress

What is ng-keypress:ng-keypress used to perform any task on keypress event..
Description of ng-keypress:ng-keypress has priority 0.Can evaluate and task on keypress event..
Syntax of ng-keypress:
<element ng-keypress="expression">

</element>
or


<input ng-keypress="expression"/>
How to Use ng-keypress/ng-keypress Example::
 Example 1:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr" ng-init="mycount=1">
        <div>
            Angularjs Example of ng-keypress
             value of mycount before ng-keypress:   {{mycount}}
            <input ng-keypress="mycount=mycount+1" />
            value of mycount after ng-keypress:   {{mycount}}
        </div>
    </div>
</div>

Example 2:
<div ng-app="webapp">
    <div ng-controller="angularjsexampleCtlr" ng-init="mycount=1">
        <div>
            Angularjs Example of ng-keypress
            value of mycount before ng-keypress:   {{mycount}}
            <input ng-keypress="myfun()" />
            value of mycount after ng-keypress:   {{mycount}}
        </div>
    </div>
</div>

<script>
    angular.module('webapp', []).controller('angularjsexampleCtlr', function ($scope, $http) {
        $scope.myfun = function () {
           $scope.mycount = $scope.mycount + 1;
        }
    });

</script>

No comments :

Post a comment