Please, consider the following example for understanding my question:
<button ng-class="$scope.controllerMethod($thisButton)" />
In my controllerMethod, I want to get a reference of the button who called ng-class. Is it possible?
(Something like passing $event.target in the ng-click button, so I can read the caller from the controller).
Any helps? Thanks!!
If you're hard coding each of your button in your menu, you won't need
ng-class
. Simplyng-click=doSomething('$event')
, then the rest is just like your normal Javascript, do whatever you want with$event.target
.If you want do it the angular way, each button needs to have a corresponding model in the controller.
In your controller:
In this example, ng-class will watch each button's
clicked
property, if it's true, then addhighlight
class onto this button.