angularjs - Add ng-click in link function of directive -


i have following function in link-function in directive:

var add_todos = function(todos) {      html += "<ul>";      (var = 0; < todos.length; i++)      {            html += '<li> <input type="checkbox">'+ todos[i].title;            add_todos(todos[i].children);            html += '</li>';      }      html += "</ul>";  }; 

i use element.replacewith(html). works well, want use ng-ifin checkbox. however, if did html += '<li> <input type="checkbox" ng-click="myfunction()">'+ todos[i].title;, wouldn't work, because, html isn't evaluated angular anymore.

i know if used template, evaluate ng-click(), don't know how use template while maintaining linking function. i've been thinking having angularjs regard html template, mean evaluate ng-click(). have no idea, however, how this. other, perhaps more efficient means of getting work, welcome too, of course.

you should use $compile service:

var add_todos = function(todos) {     var html = '…';      var mylistelement = $compile(html)($scope);     element.replacewith(mylistelement); }; 

but please don't overused $compile. in example, template ngrepeat seems far better idea!


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -