Get button value using ng-click or ng-model

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

this code example:

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

+6
source share
1 answer
 <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 can also declare your object in the controller

 $scope.data = {}; 
+17
source

Source: https://habr.com/ru/post/982239/


All Articles