Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass value from a textbox to a function in AngularJs?

Tags:

angularjs

My HTML:

<input type ="text" ng-model="contactid" >

I want to pass the contactId value entered in this box to a function abc() which is called onclick of submit button after the box.

How do I do this?

like image 436
Vishal Mahuli Avatar asked Feb 06 '23 17:02

Vishal Mahuli


1 Answers

You can do it like so:

<form ng-controller="formCtrl">     
    <input type="text" name="name" ng-model="inputValue" />
    <button ng-click="abc(inputValue)"></button>
</form>

Or using ng-submit directive:

<form ng-controller="formCtrl" ng-submit="abc(inputValue)">     
    <input type="text" name="name" ng-model="inputValue" />
    <button type="submit"></button>
</form>

And in your formCtrl controller:

.controller('formCtrl', function () {
    $scope.inputValue = null;
    $scope.abc = function (value) {
        console.log(value);
    };
});
like image 138
pgrodrigues Avatar answered Feb 13 '23 05:02

pgrodrigues