Midnight_Blaze Midnight_Blaze - 7 months ago 25
AngularJS Question

How to add an element with a click event to an angular scope at runtime

So far I've the following function called onGroundUserClick on the Scope passedScope.

I want to set it up so a function running when the iframe is loaded will set up ng-click.

var $tdName = $("<td/>", {
"class": "name",
"ng-click": "passedScope.onGroupUserClick(this)",

When I open the developer console in Chrome I see the ng-click attribute was indeed added to the button but it does not fire up the event.

a class="link" ng-click="passedScope.onGroupUserClick(this)" href="">Account Manager a

Any advice will be greatly appreciated.. I'm kind of stuck here.


After you have added the element to the DOM, call $scope.$digest(); to prime the model and the UI to "sync up". You can find a more thorough explanation here:

$scope.$digest(); documentation