$sce.TrustAsUrl not Working

2.9k views Asked by At

I am trying to create an app using angularjs where the input is taken from the input box and is displayed. It is similar to a chat. So the input can contain urls and I am converting them to links with the help of Autolinker.js which I found in this SO question How to replace plain URLs with links? . To inject html in angular binding I am using ngSanitize but I want only the urls to be changed to links and anything like 2<3 should be printed as 2<3 but should not be read as HTML tag.

I even used $sce but it didnt work. It is giving an error Parse Error with 2<3

There is a better option using linky but it is not able to convert urls without http. Fiddle with the 3 options:http://jsfiddle.net/JY3Za/58/ (PS:Here I just used a RegEx for testing)

So what would be the best way to inject html in angular while using the Autolinker.js so that only and tags are allowed but anything other than these should be displayed as plain text..?

1

There are 1 answers

7
Dayan Moreno Leon On BEST ANSWER

you where passing the wrong arguments to your

$sce.trustAsHtml

http://jsfiddle.net/JY3Za/59/