Question

I'm creating a cross platform app using phonegap and angularjs targeting it for Android Devices. I don't know how can I retrieve values from a button, for example:

<button ng-click="add()" id="add" value="{{prenotation}}">add</button>

and in javascript I use:

angular.element("#add").val();

but returns always the same value (the first). How can I retrieve the value of the button that I click??

Was it helpful?

Solution

You can send the event along with the ng-click method like:

<button ng-click="add($event)" id="add" value="{{prenotation}}">add</button>

The event knows what element was used on:

 $scope.add = function(event){
    var element = angular.element(event.toElement);
    console.log(element.val());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top