I searched in google. Got some related links from stackoverflow. I implemented that script in my code all that code not working fine. Basically I followed this link ng-click not working in dynamically created content That one is working fine without clicking my Click Here
link. I mean automatic fired to invite()
function. Pleas check below my code -
function test($scope){
$scope.email_output = 'Email already exist. <strong><a href="" ng-click="invite();">Click Here</a></strong> to Invite';
$scope.invite = function(){
alert("Hello world");
};
}
angular.module('myApp').controller('test', test);
HTML
<div ng-controller="test">
<div ng-if="email_output" ng-bind-html="email_output"></div>
</div>
I got my dynamic HTML content. But I saw ng-click
not present in my HTML content. See my output :
<div ng-bind-html="email_output" ng-if="email_output" class="ng-binding ng-scope">Email already exist. <strong><a href="">Click Here</a></strong> to Invite</div>
Please help me I am new in AngularJS. How to get my ng-click
attribut in dynamic html content?
Edit:-
See here my change code -
var email_result_html = 'Email already exist. <strong><a href="" ng-click="invite();">Click Here</a></strong> to Invite';
var temp = $compile(email_result_html)($scope);
angular.element(document.getElementById('email_result')).append(temp);
<div ng-if="email_result" id="email_result" ng-bind-html="email_result"></div>
Error Output: