2
votes

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

1 Answers

0
votes

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.