AngularJS ng-click event does not work when configured on an element coming from an asynchronous request

0

I have a page called DLL.php that contains a DataTable ( link ). I used the DataTable plugin's interface to dynamically load the contents of the DataTable. The last column of the table contains only checkboxes. I want these checkboxes to trigger the $ scope.update () event that I implemented in the OpcoesCtrl controller, but I can not, nothing is displayed in the browser toolbox console, perhaps because the checkboxes are loading dynamically, because when I use an element of the page itselfDT.php list as event trigger $ scope.update () my implementation works as expected.

Note: checkboxes are within the context of the OpcoesCtrl controller.

Question: How to use the checkboxes to trigger the event in question?

    
asked by anonymous 20.03.2015 / 16:49

1 answer

2

AngularJS compiles your Angular template (which without Angular would be static HTML) when the page loads in the browser. It is at this point that he recognizes the directives and makes internal connections to listen for events in elements that contain directives.

If you add elements to the page later, this will be "dead text" - Angular will not "see" any directives there.

Run "$ compile" on the HTML snippets you dynamically load / build, before adding them to the page - this will cause the angle to "see" the directives there. But I have not tested here what the scope would be like for this, since you have to run the $ compile on the elements before you add them to your final position - it might not work.

If all else fails, use the good old javascript "onclick" on the elements you create dynamically.

    
20.03.2015 / 17:03