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?
ng-attr is used for add or not the attribute in context. If the expression {{undefined || null}} , the attribute is not added otherwise if has a value then attribute is added with the value {{ value }} . The most common cases is in interpolation.
Angular elements are Angular components packaged as custom elements (also called Web Components), a web standard for defining new HTML elements in a framework-agnostic way.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With