Crhistian Ramirez Crhistian Ramirez - 21 days ago 8
AngularJS Question

The id from binded html does not appear in the DOM

I'm using ng-bind-html and have a div with a class and an id.

<div class="myCustomClass" id="myCustomID">My Content</div>


When I inspect the element I can see the class but the ID is missing. Here is a working plunkr illustrating the issue: https://plnkr.co/edit/iHeQQI?p=preview

Answer

You need to process you html source with $sce service like this:

app.controller('Ctrl', function($scope, $sce) {
  $scope.html = $sce.trustAsHtml('<div id="myID" class="myClass">Inspecting this element shows the class but not the ID</div>');
});
Comments