0

My js object contains double quotes so I store data in the form:

var data = "un <a ui-sref="app.concept({id:1})">test link<\/a>"

which means <a ui-sref="app.concept({id:1})">test link<\/a>

how can I decode the html entities and then compile the ui-sref? Using this https://github.com/incuna/angular-bind-html-compile only doesn't work.

It prints <a ui-sref="app.concept({id:1})">test link<\/a> in the view

alfredopacino
  • 2,979
  • 9
  • 42
  • 68

1 Answers1

0

I think it may be better/easier to store that data as an actual unescaped html string. This would require much less work.

However, if you can't do that, then you may want to inject the $sce service into your controller and then use the data = $sce.trustAsHtml(data) after your data variable declaration.

After doing this, use <div ng-bind-html="data"></div> in the view. It should fix your issue.

If that doesn't completely work, you can try to unescape the data variable using a function in underscore called unescape. So trustAsHtml(_.unescape(data)) can help you.

Router UI addition

Since you are using router-ui, your best bet is probably to do as suggested in this answer and just use href="path/to/state1" if possible.

Community
  • 1
  • 1
Jon
  • 2,456
  • 21
  • 28
  • I have a ui-sref directive in the string, ng-bind-html doesn't compile. – alfredopacino May 02 '17 at 18:24
  • @alfredopacino I just modified my answer. I think that if you are going this route, then you may just want to do what I suggest and not use ui-sref at all. – Jon May 02 '17 at 18:48
  • yeah I guess I would use the href solution (we know it's not the best option but it's better than encode the quotes..) – alfredopacino May 02 '17 at 18:56