Skip to content Skip to sidebar Skip to footer

Ionic Getting Textbox Value

Hi I'm new to ionic and I have the following html and js code. I am trying to get the value of user input on textbox upon clicking on the button. (If possible, I would like to stor

Solution 1:

Ionic works with angular which has two way binding as its core principal. There are lots of way to accomplish this but one way is to set a model of an html item. So if you set your input to have an ng model

<ion-inputtype="text" value="" [(ngModel)]="inputName"></ion-input>

and then in your controller(class) you'll have

this.inputName;

It will hold the value changes from html.

Solution 2:

I am not sure about ionic2 but in ionic 1 we can do like below:

Here is an example to store the value of use input text into and object

<inputtype="text" ng-model="username">
<inputtype="text" ng-model="password">
<button class="button"ng-click="login(username,password)"> submit</button>

in your js file

$scope.login= function(username,password){
   console.log(username);
   console.log(password);
var loginUser = {
     "username":username,
     "password":password
};
console.log(loginUser);

check this answer it always work for me.

Solution 3:

Use this:

<inputtype="text" name="input name" ng-model="variable-to-bind" />

You can access variable-to-bind from controller using $scope .

For example:.

  • In your case variable-to-bind is username, you can access it like $scope.username

Post a Comment for "Ionic Getting Textbox Value"