最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ng-bind-html does not work - Stack Overflow

programmeradmin4浏览0评论

please look at this fiddle

please type 4 in the text area, it should write an error message, that is in this line:

   $names.push('<div ng-bind-html-unsafe="snippet"></div>');

actually it does not. It prints the html code itself without handling,

and the underlying html is:

<li ng-repeat="user in list|splitList:appUsers" class="ng-scope ng-binding">
        &lt;div ng-bind-html="snippet"&gt;&lt;/div&gt;
    </li>

I tried to follow solutions from this topic

but nothing seem to help,

any help in fixing it will be regarded,

please look at this fiddle

please type 4 in the text area, it should write an error message, that is in this line:

   $names.push('<div ng-bind-html-unsafe="snippet"></div>');

actually it does not. It prints the html code itself without handling,

and the underlying html is:

<li ng-repeat="user in list|splitList:appUsers" class="ng-scope ng-binding">
        &lt;div ng-bind-html="snippet"&gt;&lt;/div&gt;
    </li>

I tried to follow solutions from this topic

but nothing seem to help,

any help in fixing it will be regarded,

Share Improve this question edited May 23, 2017 at 11:43 CommunityBot 11 silver badge asked Oct 8, 2012 at 17:13 Aladdin MhemedAladdin Mhemed 3,9719 gold badges44 silver badges58 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 13

I got help from the chat room of angularjs,

the thing is that I should use:

<div ng-bind-html-unsafe="user">...</div>

instead of {{user}}

To get it to work you will need the following:

Declare it in html

div ng-bind-html="{expression}"></div> 

Or

div class="ng-bind-html: {expression};"></div>

AND

reference angular-sanitize.min.js and then add

angular.module('YOUR_APP_NAME', ['ngSanitize']);

The last two are in the angularjs documentation for some reason...

发布评论

评论列表(0)

  1. 暂无评论