Get value from ion-input

Hi all!

I hope this is the right category

I installed all the new version of all… I think. ionic info says:

Ionic:
Ionic CLI : 6.12.4 (/Users/xxxxxx/.nvm/versions/node/v10.23.2/lib/node_modules/@ionic/cli)
Ionic Framework : ionic1 1.3.2
@ionic/v1-toolkit : 3.2.15
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v10.23.2 (/Users/xxxxxx/.nvm/versions/node/v10.23.2/bin/node)
npm : 6.14.10
OS : macOS Mojave

now the question. I started from a previous code, I need to get the value of an ion-input
I have the template (login.html)

Email Login

and the corresponding loginCtrl.js

angular.module(‘xxx.Login.Controller’, )

.controller(‘LoginCtrl’, function(GlobalVariables, SupportServices, $scope
, $rootScope, $state, $ionicModal, $http, $ionicLoading
, $ionicPopup, $timeout, $q, $stateParams, …) {

var me = this;

$scope.data = {
tmp_email: “test”
};

$scope.login = function() {
alert($scope.data.tmp_email);
};

when I click the button the alert says “test”… also if I write in the input box everything else

I have tried all… I think
[(ngModel)]
ng-model
ng-Model

no way to get the value entered by the user…

someone can help me? thanks!!!

Helping?

You seem to be working in angularjs, you are aware of that?

[(ngModel)] is Angular is angularjs revamped - for quite a while now. And solutions in Angular dont work in angularjs (likely)

Hi Tommerton… seems not working.
To be sure, I made a test with the app created by Ionic (when you make “ionic start myApp tabs” to create a test app).
I put in the tab-chats.html the input.

<ion-view view-title="Chats">
  <ion-content>
    <ion-list>
      <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" href="#/tab/chats/{{chat.id}}">
        <img ng-src="{{chat.face}}">
        <h2>{{chat.name}}</h2>
        <p>{{chat.lastText}}</p>
        <i class="icon ion-chevron-right icon-accessory"></i>

        <ion-option-button class="button-assertive" ng-click="remove(chat)">
          Delete
        </ion-option-button>
      </ion-item>
    </ion-list>
    
    <ion-item>
      <ion-label position="stacked">Email</ion-label>
      <ion-input id="email" type="email" placeholder="Enter Email" ng-model="input.field1" ></ion-input>
    </ion-item>

  </ion-content>
</ion-view>

and in controllers.js the code for visualizing, after 5 seconds, the value

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope) {})

.controller('ChatsCtrl', function($scope, Chats) {

  $scope.chats = Chats.all();
  $scope.remove = function(chat) {
    Chats.remove(chat);
  };
  
  $scope.input={
    field1:''
  }

  $scope.$on("$ionicView.afterEnter", function(event, data) {

      setTimeout(function() {
        alert($scope.input.field1);
    }, 5000);

  });

})

.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);
})

.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
});

and, also if I put something in the edit, the result is always the same… empty…

The only thing I can think of that may want to use fat arrow instead of function?

I am not into angularjs

The other thing is trying to use regular input instead of ion-input. LIkely more examples available on the net in angularjs. If you get that to work…

Sorry…

I found a solution. I have NOT to use ion-input, but simply input…
Now my code is

in the template:

      <ion-label class="dark-textColor label" >EMAIL</ion-label>
      <input class="login-input" type="text" placeholder="Enter Email" ng-model="user.email"></input>
       
      <ion-label class="dark-textColor label">PASSWORD</ion-label>
      <input class="login-input" type="password" placeholder="Enter Password" ng-model="user.password"></input>

      <button class="button-login button button-full startButton" ng-click="login(user)" style="">Login</button>

and in the controller:

  $scope.login = function(user) {

    console.log(user.email);
    console.log(user.password);

  };

Now works. I wonder why with ion-input doesn’t work…