kaytrance kaytrance - 5 months ago 35
AngularJS Question

ng-bind-html with ng-sanitize' linky output tags as strings

If I try to use both ng-sanitize's

filter with
directive, it will transform initial string

Well, <b>this is bold</b>, but this should become link http://www.example.com Lets test it!

to one having link transformed to html link, but not having bold text - it will be outputed as text having tags in it.

Here's [DEMO]

My question is how do I get in result both bold text and normal html link if initialy I have just as string having some text surrounded by tags and text that looks like a link??


Plunkr Demo

You could write a custom filter to do the work of linky and put the tags back in... (this probably isn't super robust and I'm not the best at regexes, but if it works for everything you need it to, then it gets the job done.)

module.filter('linkyWithHtml', function($filter) {
  return function(value) {
    var linked = $filter('linky')(value);
    var replaced = linked.replace(/\&gt;/g, '>').replace(/\&lt;/g, '<');
    return replaced;


<div ng-bind-html="expr | linkyWithHtml"></div>