1.0.6 • Published 8 years ago
ng-linkify v1.0.6
ng-linkify
An AngularJS module for creating hyperlinks in text. Supports web links and email addresses with or without schemes.
Setup
Install with npm
npm install ng-linkify --save
Include dist/ng-linkify.min.js
in your AngularJS application.
<script src="node_modules/ng-linkify/dist/ng-linkify.min.js"></script>
Add linkify
dependency to your module
var myModule = angular.module('app', ['linkify']);
Usage
Add linkify attribute to any element containing text you want to linkify. Nested elements text is also linkified.
<p linkify>Links such as www.npmjs.com/package/ng-linkify, https://github.com and
cpt.james.kirk@starfleet.com are clickable!</p>
<div linkify>
<p>Nested links such as npmjs.com are clickable too</p>
</div>
Inject linkify
service into controller
angular.module('app')
.controller('ExampleCtrl', ['$scope', 'linkify', '$sce', function ($scope, linkify, $sce) {
var text = 'Links such as www.npmjs.com/package/ng-linkify, https://github.com and ' +
'cpt.james.kirk@starfleet.com are clickable!';
$scope.text = $sce.trustAsHtml(linkify.createLinks(text));
}]);