0

I have seen many people ask this question, however the answers are so complicated that they do not make sense, neither do the fiddles. I am having an issue with ngSanitize removing my ng-click links on elements. Some say there must be a $compile directive to get this fixed but I do not understand how it works.

I have not tried the $compile option because the baseline examples provided on the internet do not fit what I am trying to do. I simply need ng-bind-html to retain my ng-click functions.

This PHP creates the links given back to the Angular App through $http.

while ($row = mysqli_fetch_array($result)) {

    $response = $response."<br>".$row[2]."<br><a class='btn btn-primary text-white' data-ng-click='injectSample(".$row[0].", ".$category.")'>Select</a><hr>";

}

This is the function that will test out my parameters.

$scope.injectSample = function(id, cat) {
    console.log("test");
    console.log("Injecting Sample "+id+" from category "+cat+".");
}

This is the HTML where the ng-bind-html exists

<div class="modal-body" ng-bind-html="samples">
      </div>

Right now the "Select" link is created and the button shows, but ng-click is removed by ngSanitize.

Matthew Walker
  • 193
  • 1
  • 15
  • I found the ngHtmlCompile script here, instead of using `ng-bind-html` it allowed me to compile the html with the ng-click by using `ng-html-compile` instead. This worked easy, if anyone else has this same issue! https://github.com/francisbouvier/ng_html_compile – Matthew Walker May 27 '19 at 22:33
  • The server should just return the data from the database query, not build HTML. AngularJS should build the DOM from the data. – georgeawg May 27 '19 at 22:36

0 Answers0