.controller('loginctrl', function($scope, $rootscope, $http, $state) { window.localstorage.removeitem("loggedin"); if(window.localstorage.getitem("loggedin") == undefined) { $scope.dologin = function() { var username = $scope.fname + " " + $scope.lname; console.log(username); //store login information window.localstorage.setitem("username", username); window.localstorage.setitem("password", $scope.password); window.localstorage.setitem("loggedin", true); $http.post('http://localhost:8000/login',{ username: window.localstorage.getitem("username"), password: window.localstorage.getitem("password"), token: $rootscope.devtoken, platform: ionic.platform.platform() }); alert("login success"); $state.go('main'); }; } else { alert("login success"); $state.go('main'); } })
<ion-content ng-controller="loginctrl"> <form ng-submit="dologin()" style="display: block; margin: 100px"> <div class="list"> <label class="item item-input"> <input type="text" ng-model="fname" placeholder="first name"> </label> <label class="item item-input"> <input type="text" ng-model="lname" placeholder="last name"> </label> <label class="item item-input"> <input type="password" ng-model="password" placeholder="password" style="text-align: center"> </label> <label class="item"> <button class="button button-block button-positive" type="submit">register</button> </label> </div> </form> </ion-content>
i trying text html field fname , lname using $scope.fname because fname ng-model. how come returning undefined? have controllers set properly. can't figure out why username outputting undefined? trying load app @ login.html , once logged in, change state home.html. use doing this.
the ion-content
creates own child scope. try declaring main scope object in controller:
.controller('loginctrl', function($scope, $rootscope, $http, $state) { $scope.data = {}
in template:
<input type="text" ng-model="data.fname" placeholder="first name">
in login submit:
var username = $scope.data.fname + " " + $scope.data.lname;
Comments
Post a Comment