How to retrieve the value from textbox using AngularJs?

Naga Bhavani picture Naga Bhavani · Aug 6, 2015 · Viewed 34.7k times · Source
$scope.add=function()
                {
                    //How to retrieve the value of textbox
                }

<input type='text'><button ng-click='add()'></button>

When I click on the button, how can I retrieve the textbox value in the controller and add that value to the table dynamically?

Answer

Pankaj Parkar picture Pankaj Parkar · Aug 6, 2015

Assign ng-model to it so that variable will be available inside scope of controller.

Markup

<input type='text' ng-model="myVar"/>
<button type="button" ng-click='add(myVar)'></button>