1

I am newbie of AngularJS. I want NOT to escape HTML tag, so

  1. include angular-sanitize.js
  2. write the code below:
<!-- <div>{{article.content}}</div> --> <div ng-bind-html="{{article.content}}"></div> 

But nothing is being rendered.

1
  • Have you included sanitize like this: angular.module("myapp", ["ngSanitize"])? Commented Sep 9, 2014 at 9:00

2 Answers 2

3

You don't need the braces:

<div ng-bind-html="article.content"></div> 

you also need to make sure angular knows that it's safe in your controller:

$sce.trustAsHtml($scope.article.content); 
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure $sce is needed if you don't link sources outside the application? The other answer's plunker seems to work fine without.
True, I'm not sure how - in all the angular docs it says you have to sanitise the output and I've had experience with things that don't work unless you mark them to be trusted. It's possible that it's dependent on what the source is - I was pulling info back from a web service, maybe angular trusts local strings and functions implicitly. That's just my supposition though, not fact.
2

I think this will be help you.

plunker

var app = angular.module('app', ['ngSanitize']); app.controller('appCtrl', ['$scope', '$sce', ctrl]); function ctrl($scope, $sce) { $scope.getContent = function() { return "shohel rana"; }; } 
<body ng-controller="appCtrl"> <h1>Hello Plunker!</h1> <div ng-bind-html="getContent()"></div> </body> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.