Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get button value with ng-click or ng-model

Tags:

angularjs

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.

like image 425
afrila gunadi Avatar asked Feb 10 '15 03:02

afrila gunadi


People also ask

Can we use NG-model in button?

The ng-model directive can also be applied to the input elements such as the text box, checkboxes, radio buttons, etc. Let's look at an example of how we can use the ng-model with the “textbox” and “checkbox” input type.

What is the difference between Ng-click and Onclick?

Ans1: The execution context is another key difference between ng-click and onclick. An expression inside of ng-click runs against a specific scope object, often the scope object representing the model for the current controller, whereas code inside an onclick attribute executes against the global window object.

Can we use NG-click and Onclick together?

For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.

What is the use of NG-click?

The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can pop up an alert when the button is clicked.


1 Answers

<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 = {};
like image 174
yangli-io Avatar answered Oct 17 '22 23:10

yangli-io