0

I have a angularjs project where data come from database. and bind in html template. some data inserted from text editor, and i need to show the data in html template like @html.raw in mvc. is it possible.

4
  • Include angular-sanitize and bind like this: <p ng-bind-html="myHtmlVariable"></p> Commented Sep 29, 2016 at 12:53
  • when i am using $scope.item = '<p style="color:black;">I am an <code>HTML</code>string with ' + //'<a href="#">links!</a> and other <em>stuff</em></p>'; it work .And when $scope.item bind from database not working. Commented Sep 29, 2016 at 12:55
  • That's why I said to use the angular-sanitize library, that's what it partially is made for Commented Sep 29, 2016 at 13:00
  • Does user specifically insert HTML code via text editor? Commented Sep 29, 2016 at 13:28

3 Answers 3

1

Check out the angular-sanitize module. I've created a plunk to demonstrate how it works: Check this plunk

<body ng-app="app" ng-controller="testController">
    <div ng-bind-html="customHtmlContent">
    </div>
</body>

angular.module('app', ['ngSanitize']).controller('testController',
    function($scope, $sanitize){
        $scope.customHtmlContent = $sanitize('<strong>Lorem ipsum dolor</strong>');
    });
Sign up to request clarification or add additional context in comments.

Comments

0

angular sanitize is a good option as I have used it into my project.

Comments

0

Just use

<div class="blog-main-descripton" ng-repeat="d in Htmlrow">
            <p ng-bind-html="d.value"></p>
        </div>

and my code is runing

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.