In this article I will explain with an example, how to use ng-cut directive in AngularJS.
 
 

HTML Markup

The following HTML Markup consists of:
DIV – For applying ng-app and ng-controller AngularJS directives.
Note: If you want to learn more about these directives, please refer my article Introduction to AngularJS.
 
TextBox – For capturing user input.
The HTML INPUT TextBox has been assigned with the following AngularJS directive.
ng-cut – Called when the text in the TextBox is being cut.
SPAN – For displaying message.
<div ng-app="MyApp" ng-controller="MyController">
    <input type="text" ng-cut="Cut()" value="ASPSnippets" />
    <hr />
    Cut: <span style="font-weight:bold">{{Cutted}}</span>
</div>
 
 

Implementing ng-cut Directive

Inside the HTML Markup, the following AngularJS script file is inherited:
1. angular.min.js
Then, inside the Controller, the Cutted variable is set to FALSE.
When the text in the TextBox is being cut, the Cut function is called and it is also called if the (Ctrl + x) is pressed on keyboard without even selecting any text.
Inside this function, the Cutted variable is set to TRUE, which will be later displayed on the page using SPAN element.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script type="text/javascript">
    var app = angular.module('MyApp', [])
    app.controller('MyController', function ($scope) {
        // By default false.
        $scope.Cutted = false;
        $scope.Cut = function () {
            // Set to true.
            $scope.Cutted = true;
        }
    });
</script>
 
 

Screenshot

ng-cut example in AngularJS
 
 

Demo

 
 

Downloads