0

So, what do i have:

  • Text that contains smiles like :) :( :\
  • A filter that replace smiles with img tag
  • DIV with {{ message | smiles }}

Like you know, the {{}} converts all html tags to html entities.

So i get: Message that contains smile <img src="/smile.gif">

I tried to use ng-bind-html and $sanitize, but it's do not sanitaize "good" html tags like <b>, <a>, etc...

I want to apply my smiles filter AFTER that message variable be sanitized. And i dont know how to do that.

EDIT1:

message variable contains "here message with smiles :) :( :\"

Filter that converts 'smiles' to img tag:

angular.module('my.filters', [])
.filter('smiles', function () {
  return function (input) {
    return input.replace(/:\)/gi, '<img src="/images/smile.gif">');
  }
});

The DIV element:

<div>{{ message | smiles}}</div>

When it's rendered i get:

here message with smiles <img src="/images/smile.gif">

and not here message with smiles

MrSil
  • 608
  • 6
  • 12

1 Answers1

0

are you sure you're injecting ngSanitize in your module and using ng-bind-html?

here's a working example: http://plnkr.co/edit/IEovofjHDMleLZlb9AMJ?p=preview

gru
  • 4,573
  • 1
  • 22
  • 22
  • `ngSinitize` and `ng-bind-html` doesn't help here, coz `ng-bind-html` don't remove html tags. I dont want to allow to users use of any html tags. So i need apply filter AFTER that message been sanitized(all html\script tags removed) – MrSil Mar 27 '14 at 13:07
  • so it seems that your question is not correctly formed. isn't something you would do in your filter? you'd bind user input to an ng-model and print out the filtered model wherever you need it. in your filter you can then strip all the tags if you don't want them, just matter of playing a bit with regexes – gru Mar 27 '14 at 14:00