0

I'm beginner with angular, and I don't know how to get an attribute 's value. As exemple, I have a button with a value attribute, and I'would like to get that value to play with, when I call a function, in this case the function changeArea, here is the code.

In this case I want to get the value of the value attribute which is 0. But I have no idea on the way I can access it.

<button class="btn btn-{{ (gesture.area_id == '0') && 'primary' || 'default' }}" 
    type="button" 
    value="0" 
    ng-click="changeArea(gesture.area_id,gesture.id)">
</button>

EDIT:

Let'say I have several buttons and I need them to have a unique value. Can I do something like that to the others value attribute: {{myButtonValue+1}} and then for the other {{myButtonValue+2}} and so on ? Sorry, I can't test it at the moment, that's why I ask.

2 Answers 2

1

When you do ng-click you can pass the click event $event to your function.

<button class="btn btn-{{ (gesture.area_id == '0') && 'primary' || 'default' }}" 
    type="button" 
    value="0" 
    ng-click="changeArea(gesture.area_id,gesture.id,$event)">
</button>

Then in your $scope.changeArea you can do this:

$scope.changeArea = function (param1, param2, e)

From there you should be able to grab the elements values.

https://docs.angularjs.org/guide/expression#-event-

Sign up to request clarification or add additional context in comments.

Comments

0

Set it to a $scope variable and use that:

<button value="{{myButtonValue}}"

And then you can do:

$scope.myButtonValue = 3; //or whatever

1 Comment

Let'say I have several buttons and I need them to have a unique value. Can I do something like that to the others value attribute: {{myButtonValue+1}} and then for the other {{myButtonValue+2}} and so on ? Sorry, I can't test it at the moment, that's why I ask.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.