退出时表单输入不会清除

时间:2015-07-06 07:48:54

标签: angularjs angularjs-scope ionic-framework

我有一个登录表单,在注销时,输入登录帐户的值在注销时不会为空。我正在构建一个离子移动应用程序

我的login.html

<form name="loginData" class="container ng-scope ng-invalid ng-pristine ng-invalid-required" error-popup="loginData" ng-submit= "loginData.$valid && doLogin(loginData)" novalidate>
        <div class="list list-inset login-form">
          <div class="form-group item item-input">
            <i class="fa fa-users"></i>
            <input type="text" name="orgCode" class="form-control ng-pristine ng-invalid ng-invalid-required" ng-model="user.orgCode" placeholder="Organization Code" required>
          </div>

          <div class="form-group item item-input">
            <i class="fa fa-envelope"></i>
            <input type="email" name="email" class="form-control ng-pristine ng-invalid ng-invalid-required ng-valid-email" ng-model="user.email" placeholder="Email Address" required>
          </div>

          <div class="form-group item item-input">
            <i class="fa fa-lock"></i>
            <input type="Password" name="password" class="form-control ng-pristine ng-invalid ng-invalid-required ng-invalid-minlength" ng-model="user.password" placeholder="Your Password" ng-minlength="8" required>
            <br/>
          </div>

          <div class="login-btn">
            <button class="button button-block button-positive" type="submit" ng-disabled="submitted">Log in</button>
          </div>
        </div>
        <div ng-if="localDB === false" class="registration-placeholder">
          <a href="#" ng-click="setView()" class="registration-link">Need an account?</a>
        </div>
      </form>

my controller.js

angular.module('loanstreet.controllers')
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $state, AuthenticationService, $location, $rootScope, $cordovaToast, $ionicPopup, $ionicLoading) {
  $scope.doLogin = function(loginData) {
    $scope.message = '';
    console.log("in doLogin")

    if(loginData.$valid) {
      $scope.submitted = true;
      $ionicLoading.show({
      //make the template a directive
        template: '<ion-spinner class="spinner-energized" icon="spiral"></ion-spinner>',
        hideOnStateChange: true,
        duration: 2000
      });
      console.log("all clear") 
      var authLogin = AuthenticationService.login(loginData);
      console.log(authLogin)
      $scope.$apply(function() {
        $scope.submitted =false;
        console.log($scope.user)
        console.log(JSON.stringify($scope.user))
        $scope.user = {};
      })

    }    
  };
  $scope.view = false;
  $scope.setView = function() {
    $scope.view = $scope.view === false ? true : false;
  }

  $scope.logout = function() {
    $scope.view = false;
    AuthenticationService.logout();
  };
})

所以基本上我要做的就是Logout,我的login.html表单中的所有输入数据都必须为空。我已经尝试过loginData。$ setPristine(),$ scope.user。$ setPristine()但都无济于事

在提交或退出时,是否还有其他方法可以清除表单中的所有数据

0 个答案:

没有答案