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?
get element by id and set new attribute and value
To Set attribute dynamically use
To get attribute value use
To remove attribute use
You need to recompile your div
http://jsfiddle.net/r2vb1ahy/
Angular2 is providing
[attr.<attribute name>]
to bind attribute values.In component class:
From http://blog.sodhanalibrary.com/2016/02/set-attribute-and-remove-attribute-with.html