Some times we required to render the html in our html view that is contained as string by models. For this purpose we can follow the following simple steps. No additional jquery library required. Just follow the following steps.
Step 1: Inject "$sce" in your controller.js file. After that paste this "$scope.renderHtml" function in your controller.js file.
myApp.controller("itemCtrl", ["$scope", "$state","$sce", function ($scope, $state, $sce) {
$scope.renderHtml = function (htmlCode) {
return $sce.trustAsHtml(htmlCode);
};
}]);
Step 2: In your html view add the "ng-bind-html" tag and assign "renderHtml" function. "renderHtml" function accept a string value that contained html.
<p ng-bind-html="renderHtml(htmlAsString)"></p>
No comments:
Post a Comment