This is my template:
<div class="span12"> <ng:view></ng:view> </div>
and this is my view template:
<h1>{{stuff.title}}</h1> {{stuff.content}}
I am getting the content
as html and I want to display that in a view, but all I am getting is raw html code. How can I render that HTML?
An Angular HTML template renders a view, or user interface, in the browser, just like regular HTML, but with a lot more functionality. When you generate an Angular application with the Angular CLI, the app. component. html file is the default template containing placeholder HTML.
A static template is defined by using script tag. It must has an id attribute with a unique value and a type attribute with value text/ng-template .
templateUrl can also be a function which returns the URL of an HTML template to be loaded and used for the directive. AngularJS will call the templateUrl function with two parameters: the element that the directive was called on, and an attr object associated with that element.
Use-
<span ng-bind-html="myContent"></span>
You need to tell angular to not escape it.
To do this, I use a custom filter.
In my app:
myApp.filter('rawHtml', ['$sce', function($sce){ return function(val) { return $sce.trustAsHtml(val); }; }]);
Then, in the view:
<h1>{{ stuff.title}}</h1> <div ng-bind-html="stuff.content | rawHtml"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With