Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  170] [ 7]  / answers: 1 / hits: 100229  / 10 Years ago, wed, september 10, 2014, 12:00:00

I'm trying to dynamically add attribute to div in controller in angular js.



 var table = document.getElementById(div_id).setAttribute(ng-click, function_name());
$scope.$apply();


Everything looks fine, in the debugger i see that attribute was added but it doesn't execute my function. Do you have any ideas how to add attributes to the existing div and how to make it works?


More From » angularjs

 Answers
5

You need to recompile your div



var el = angular.element(div_id);
$scope = el.scope();
$injector = el.injector();
$injector.invoke(function($compile){
$compile(el)($scope)
})


http://jsfiddle.net/r2vb1ahy/


[#69512] Monday, September 8, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenna

Total Points: 706
Total Questions: 107
Total Answers: 106

Location: Azerbaijan
Member since Tue, Sep 21, 2021
3 Years ago
;