Aniruddha Das
Aniruddha Das

Reputation: 21688

ng-click is removed by ngsanitize

I am getting setting some html text in my $scope variable which also contains ng-click attribute so that it on click of a link it will call angular controller function.

$scope.message = "dum messge<a data-ng-click='loadCalenderData()'>retry</a>";

//view
<div ng-bind-html="message"></div>

I tried both data-ng-click and ng-click but no luck.

Upvotes: 1

Views: 220

Answers (2)

RL89
RL89

Reputation: 1916

Because it's not $compiled. When you bind-html, that doesn't tell Angular to search through that HTML and compile directives within it. You'll need a custom directive for this.

Check this link https://www.reddit.com/r/angularjs/comments/312mbg/ngclick_on_element_inserted_using_ngbindhtml_not/

Upvotes: 2

Mikkel
Mikkel

Reputation: 7777

That's ng-sanitise's job, to prevent any unauthorized markup or script being rendered on the page.

This is a simpler mechanism that separates your error message from the markup/functionality:

//view
<div ng-bind-html="message">
<a data-ng-click='loadCalenderData()' ng-show="message">retry</a>

If you want it to depend on something else, just use a different scope variable

Upvotes: 1

Related Questions