2

I have included ngSanitize to display html in bind-html I have bind following in my code:

$scope.discslist = '<div class="items text-center"><img src="assets/uploads/discs/'+obj.image+'" class="img-circle"><br><input type="radio" id="chkDisc'+obj.id+'" name="chkDisc" value="'+obj.id+'" required data-ng-model="formdata.disc"></div>';

And in controller I have included $sanitize

It binds the html into ng-bind-html="disclist" div but only images and div are added, input element is missing from that:

<div class="items text-center"><img src="assets/uploads/discs/disc9.png" class="img-circle"><br></div>

I just wants to bind html to my div.

I am using angularjs 1.4

1 Answer 1

0

Here what I Have tried.

JS

angular.module("test",['ngSanitize'])
.controller("testCtrl",['$scope','$sce',function($scope,$sce){

    $scope.discslist = '<div class="items text-center">'+
                        '<img src="assets/uploads/discs/test.png" class="img-circle"><br>'+
                        '<input type="radio" id="chkDiscid" name="chkDisc" value="1" required data-ng-model="formdata.disc">'+
                        '</div>';

                        $scope.discslist = $sce.trustAsHtml($scope.discslist);;

}])

HTML

<body ng-controller="testCtrl">
    <div ng-bind-html="discslist"></div>

    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="angular-sanitize.js"></script>

</body>

Make sure you have include angular-sanitize.js and injected ngSanitize module in app and injected $sce in your controller.

1
  • Yes trustAsHtml works. I have angularjs min.js so no need to include external sanitize.js Commented Jul 6, 2015 at 1:25

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.