This is a great answer. Based on this, you can use it as a filter instead of:
angular.module('app', ['ngSanitize']) .filter('decoded', [ '$sanitize', function($sanitize) { function htmlDecode(input) { var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; } return function(input) { return htmlDecode(input); } }])
Then use it as follows:
<p ng-bind-html="scope_with_data | decoded"></p>
This becomes very convenient if you have third-party scripts (say, an image gallery), and you need to transfer data using the html data- * attributes. The only way to do this is to use a filter.
<div data-title="scoped_data.title | decoded "></div>
Hope this helps someone :)
Urb Gim Tam Aug 04 '16 at 13:46 on 2016-08-04 13:46
source share