0

I got this directive which renders a list of objects. this objects got it's own function, i wanna bind it to a button. So i run over my items.In my objects value, i got a prop called Action which value is a function. i then try to add it to the html string, then i say it should be trusted as html. like shown below

angular.forEach(data.Items, function (value, key) {
      var buttonsCode = "";
      buttonsCode += '<div class="btn btn-sm" ng-click="' + value.Action + '">Test</div>';
      value["buttons"] = $sce.trustAsHtml(buttonsCode);
});

but when i try to run it, it looks like this

<div class="btn btn-sm" ng-click="function () {
    alert("test of funtion"); }">Test</div>

Anyone know how i can do this?

jogo
  • 12,469
  • 11
  • 37
  • 42
DaCh
  • 921
  • 1
  • 14
  • 48
  • 1
    Check this post it will help you - http://stackoverflow.com/questions/21687925/angular-directive-how-to-add-an-attribute-to-the-element – Amit Sirohiya Mar 18 '16 at 11:38
  • Thanks for the comment Amit, I been looking at it, an from what i understand, he creates a directive that has a click event. my problem here is that i render a lots of buttons for a tabel. and can't see how i can hook the click event up with angular when rending the html for every row in the table. – DaCh Mar 23 '16 at 14:18
  • After some more trying i found that i could be done with the answer given in the comment, so i will flag this as a dublicate – DaCh Mar 23 '16 at 14:51

0 Answers0