0

I have a Scopevariable which contains the html-Code of a button with a ng-click Attribute and want to assemble the the Page dynamically.

$scope.myHtml = "<button class="someclass" ng-click="clickme()">Button</button> 

and i am currently using the html like this:

<div ng-bind-html="myHTML"></div> 

The Button displays pretty fine but the ng-click got removed, so how can i keep the angular expressions from the variable?


Thanks in advance!

3
  • 1
    There is an error in : $scope.myHtml = "<button class="someclass" ng-click="clickme()">Button</button>, it will give js error in console, don't have you checked? Commented Oct 20, 2016 at 11:24
  • 1
    Possible duplicate stackoverflow.com/questions/22737927/… Commented Oct 20, 2016 at 11:25
  • This works, thank you :) Commented Oct 20, 2016 at 12:17

1 Answer 1

0

Try it like this:

$scope.myHtml = '<button class="someclass" ng-click="clickme()">Button</button>'; 
Sign up to request clarification or add additional context in comments.

1 Comment

I did it like this, just took the wrong quotes in the Question.. sorry, But the Comment from @astrocrack seems to work :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.