Improve this Doc  View Source

linky

  1. - filter in module ngSanitize

Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and plain email address links.

Requires the ngSanitize module to be installed.

Usage

In HTML Template Binding

<span ng-bind-html="linky_expression | linky"></span>

In JavaScript

$filter('linky')(text, target, attributes)

Arguments

Param Type Details
text string

Input text.

target string

Window (_blank|_self|_parent|_top) or named frame to open links in.

attributes
(optional)
objectfunction(url)

Add custom attributes to the link element.

Can be one of:

  • object: A map of attributes
  • function: Takes the url as a parameter and returns a map of attributes

    If the map of attributes contains a value for target, it overrides the value of the target parameter.

Returns

string

Html-linkified and sanitized text.

Example

<div ng-controller="ExampleController">
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
<table>
  <tr>
    <th>Filter</th>
    <th>Source</th>
    <th>Rendered</th>
  </tr>
  <tr id="linky-filter">
    <td>linky filter</td>
    <td>
      <pre>&lt;div ng-bind-html="snippet | linky"&gt;<br>&lt;/div&gt;</pre>
    </td>
    <td>
      <div ng-bind-html="snippet | linky"></div>
    </td>
  </tr>
  <tr id="linky-target">
   <td>linky target</td>
   <td>
     <pre>&lt;div ng-bind-html="snippetWithSingleURL | linky:'_blank'"&gt;<br>&lt;/div&gt;</pre>
   </td>
   <td>
     <div ng-bind-html="snippetWithSingleURL | linky:'_blank'"></div>
   </td>
  </tr>
  <tr id="linky-custom-attributes">
   <td>linky custom attributes</td>
   <td>
     <pre>&lt;div ng-bind-html="snippetWithSingleURL | linky:'_self':{rel: 'nofollow'}"&gt;<br>&lt;/div&gt;</pre>
   </td>
   <td>
     <div ng-bind-html="snippetWithSingleURL | linky:'_self':{rel: 'nofollow'}"></div>
   </td>
  </tr>
  <tr id="escaped-html">
    <td>no filter</td>
    <td><pre>&lt;div ng-bind="snippet"&gt;<br>&lt;/div&gt;</pre></td>
    <td><div ng-bind="snippet"></div></td>
  </tr>
</table>