I want to show my data as html in angularjs. Here is apart of my codes :
<div class="panel-body" ng-controller="hosgeldinizController">
<div id="divHosgeldiniz" name="hosgeldinizMessages" ng-repeat="hosgeldinizMessage in hosgeldinizMessages">
<div>
<span ng-class-odd="'degisimIcerik'" ng-class-even="'degisimIcerik alternate'" ng-bind-html="hosgeldinizMessage.M_Icerik">{{hosgeldinizMessage.M_Icerik}} </span>
</div>
</div>
</div>
But it doesnt show as html it shows just like normal text however hosgeldinizMessage.M_Icerik contains html elements. What should I do to show as html?
If you bind to a value with HTML in it, you should use ngBindHtml.These bindings {{ foo }} prevent injecting actual HTML for security reasons.
Also check this $sce
EDIT
Install angular-sanitize and include it in your dependencies...
Angular sanitize / ng-bind-html not working?
It worked for me
In controller...
In the html
Get ngSanitize as a dependancy in your module
and use ng-bind-html in your view
but be sure to include the related versions
as in
or if you prefer it locally you download a copy https://code.angularjs.org/
point to note
well .... for some reason if you mixed them up (e.g angular 1.2.23 and angular-sanitize 1.0.0) you will end up with either a sanitized version in your view (it will work) but ALOT of ERRORS in your console or sometimes it wont render on screen at ALL :) - I believe that's what you are facing
Trust me , I 've been there :D
This line:
should be
without the
{{}}
expression.Display of the content is already taken care by the
ng-bind-html
directive.I think using ng-bind-html-unsafe will get you what you need.
Here's a working fiddle: http://jsfiddle.net/nfreitas/aHfAp/
Documentation for the directive can be found here: http://docs.angularjs.org/api/ng.directive:ngBindHtmlUnsafe