I am adding a few buttons dynamically by injecting html using jquery. I want to be able to use ng-click on those elements but I do not know how to attach an angular click listener on it.
1 Answer
To attach a click listener on a button simply add ng-click="someMethod()" to the button:
<button ng-click="someMethod()">Button text</button>
you will need have to have a scope-method called someMethod().
for reference see the angular docs and note that the expression can be replaced by a method.
2 Comments
Anil Dukkipatty
 That does not work when I add content dynamially, for ex: $('#parentDiv').html('<button ng-click="someMethod()" >click me</button>'); This is what I want to achieve.
  rakke
 The reason it is not working is that you add your element in the controller. You should probably use a directive instead. Alternatively a service. You could also use pure javascript as in this link. What are you trying to accomplish, and why do you need to add it dynamically in the controller?