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??

Était-ce utile?

La 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());
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top