3

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,

Community
  • 1
  • 1
Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56

2 Answers2

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}}

Aladdin Mhemed
  • 3,817
  • 9
  • 41
  • 56
  • 1
    **HTML** `
    ` with **js** `$scope.fruitsView = '

    sdf

    sdfdfsd

    ';` is working fine. but **HTML** `
    ` with **js** `$scope.fruitsView = '

    {{each}}

    ';` is not working.. Please have a look at this fiddle. http://jsfiddle.net/3LfU7/
    – Rajkamal Subramanian Feb 13 '13 at 05:24
  • One also need to inject angular-sanitize.js & to put as a dependency ngSanitize – JBE Dec 12 '13 at 16:09
7

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...

Derlin
  • 9,572
  • 2
  • 32
  • 53
Eldad
  • 431
  • 4
  • 3