1

I have n number of records coming from backend as HTML in array. I need to display the HTML response as HTML in my view. I tried ng-bind-html , but it takes the last value. Need assistance.

  $scope.res=  "data": [
            {
              "jd": "<p>this jd1</p>"
            },
            {
              "jd": "<li>this jd2</li>"
            },
            {
              "jd": "<ul>this jd3</ul>"
            },
            {
              "jd": "<p>this jd4</p>"
            }
          ]
        }

Html:

 <div ng-repeat="item in res">
    <div ng-bind-html ="item.jd">
    </div>

1 Answer 1

3

You can use $sce.trustAsHtml. See the documentation here.

What you could do is:

Add this line in your controller:

$scope.trustAsHtml = $sce.trustAsHtml;

And update your HTML like this:

<div ng-bind-html ="trustAsHtml(item.jd)">

Note that you should probably start using Angular 6 instead of AngularJS

Sign up to request clarification or add additional context in comments.

1 Comment

Hi , sure will do it. I have one more query. I am doing encoding and sending the html response to backend. Now I need to decode them and use it here. So I wrote a filter. DecodeFilter: app.filter('decodeFilter', function() { return function(input) { return decodeURIComponent(unescape(input)); }; });

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.