0

I;m trying to get the username from the input field and pass to the function to create a user account but the username input in the field does seem to be updated in model. enter image description here

I used window.alert to display the username just for the test purpose.

login.html

ion-view view-title="Login">
    <ion-content>

         <div class="list list-inset" padding>

            <div class="item-divider" align="center"> Login</div>

            <label class="item item-input">
                <span class="input-label">UserName</span>
                <input  ng-model="username" type="text" placeholder="Email">
            </label>

            <label class="item item-input">
                <span class="input-label">Password</span>
                <input  ng-model="password" type="password" placeholder="Your Password">
            </label>  

        </div>
         <center><button class="button button-positive " ng-click="log()">Login</button> </center>

app.js (not the whole code)

blog.config(function($stateProvider,$urlRouterProvider){
    $stateProvider
        .state('mainlist',{
        url:'/mainlist',
        templateUrl:'templates/MainList.html',
        controller:'listCtrl'
    })
        .state('login',{
        url:'/login',
        templateUrl:'templates/login.html',
        controller:'loginCtrl'
        });
blog.controller('loginCtrl',function($scope)
                {
                        $scope.log=function()
                        {
                            var username= $scope.username;
                            window.alert(username);
                        }

                    }
               );
2

2 Answers 2

0

You need first to define the model. Change your code to this and it should work(not tested):

blog.config(function($stateProvider,$urlRouterProvider){
    $stateProvider
        .state('mainlist',{
        url:'/mainlist',
        templateUrl:'templates/MainList.html',
        controller:'listCtrl'
    })
        .state('login',{
        url:'/login',
        templateUrl:'templates/login.html',
        controller:'loginCtrl'
        });


blog.controller('loginCtrl',function($scope)
                {

                        $scope.username = "";
                        $scope.log=function()
                        {
                            var username= $scope.username;
                            window.alert(username);
                        }

                    }
               );
Sign up to request clarification or add additional context in comments.

Comments

0
<label class="item item-input">
                <span class="input-label">UserName</span>
                <input  ng-model="data.username" type="text" placeholder="Email">
 </label>

app.js

blog.controller('loginCtrl',function($scope)
            {
                    $scope.data={};
                    $scope.log=function()
                    {
                        var username= $scope.data.username;
                        window.alert(username);
                    }

                }
           );

enter image description here

2 Comments

better use controllerAs pattern while defining controller
im just learning Angularjs , thanks for the sugesstion

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.