- AngularJS has $linky() filter for filtering email, http and ftp resources from the text.
- In ngSanitize module has the definition of the $linky filter and present in angular-sanitize.js file.
- In this Demo, "We will use $linky filter for filtering email,http and ftp key values from text".
- Below code has both HTML and JavaScript implementation of $linky filter from a input text in text area and display in browser.
<!DOCTYPE html> <html ng-app="myApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-sanitize.js"></script>
<meta charset="utf-8">
<title>AngularJS linky Filter Example</title>
</head>
<body ng-controller="MyController">
<h3>Using linky filter in HTML</h3>
<textarea ng-model="inputText" cols="50" rows="10">
</textarea>
<div ng-bind-html="inputText | linky"></div>
<h3>Using linky filter in JavaScript</h3>
<div ng-bind-html="testString"></div>
<script>
var myApp = angular.module("myApp", ['ngSanitize']);
myApp.controller("MyController", ["$scope", "$filter", function($scope, $filter) {
$scope.inputText = "HI This is AngularJS Demo.We are testing linky filter.Please check my blog http://www.tutorialsavvy.com for more articles in AngularJS.you can also contact me in the following email address sandeeppateltech@gmail.com .";
$scope.testString = $filter('linky')("hi my alternate email is sandeep_giet@yahoo.com .");
}]);
</script>
</body>
</html>
- The output of the above code is embedded in the below JSBIN link.