afrila gunadi
afrila gunadi

Reputation: 124

get button value with ng-click or ng-model

I have a problem with the angular, I have a more than button with value 1 - 9, I would if I click the button 1. value of input type="text" automatic be 1..

this example code :

<input type="text" class="tags" ng-model="data.tes">
<br>
<button value="1" class="phoneNumber" ng-model="data.tes">1</button>

any suggestion for me?

Thanks in advance.

Upvotes: 7

Views: 22508

Answers (1)

yangli-io
yangli-io

Reputation: 17334

<button class="phoneNumber" ng-click="data.tes = 1">1</button>

For more than 1 button

in your controller

$scope.buttons = [1,2,3,4,5,6,7,8,9]

and in your markup

<button ng-repeat="button in buttons" ng-click="data.tes = button">{{button}}</button>

EDIT

You may want to declare your object in the controller as well

$scope.data = {};

Upvotes: 19

Related Questions