angularjs - Angular1.3: ng-bind-html not working when trying to load html elements/tags in a string? -
i trying render html tags in string example: ("<div>test</div><p></p>......")
pulled json data, usual $sce.trustashtml() filter below not work reason , renders string plain text:
myhtmlfilter.js :----
angular .module('myapp.htmlfilter', []) .filter('html', ['$sce', function ($sce) { return function (text) { return $sce.trustashtml(text); }; }]);
index.html:----
<div ng-bind-html='view2.loadedjson.htmltextstring | html'></div>
it seem work if hardcode html directly filter below:
<div ng-bind-html='"<strong>test</strong>" | html'></div>
would know going wrong?
you need include ngsanitize in app. docs (https://docs.angularjs.org/api/ng/directive/ngbindhtml):
to utilize functionality, ensure $sanitize available, example, including ngsanitize in module's dependencies (not in core angular). in order use ngsanitize in module's dependencies, need include "angular-sanitize.js" in application.
you need change first line in script , make include link angular sanitize js file in html:
angular.module('myapp.htmlfilter', ['ngsanitize'])
Comments
Post a Comment