如何在angularjs中提交后关闭模态

时间:2016-11-10 09:38:47

标签: angularjs angular-ui-bootstrap

我知道这个问题有很多结果,但没有人给我工作答案。

html 1:

<button class="basebtn logbtn" ng-click="openlog()">LOGIN</button>
<button class="basebtn regbtn" ng-click="openreg()">SIGN UP</button>

html 2:

<div ng-controller="main">
<center><img class="img-login" ng-src="../images/form-logo.png"/></center>
<form class="login" name="log" ng-submit="login()" novalidate>
    <div class="form-group  login-form" ng-class="{'has-error' : isInvalid(log.email) ,'has-success' : isValid(log.email)}">
        <input type="email" class="form-control" name="email" ng-model="user.email" required placeholder="Email">
        <div class="alert alert-danger" role="alert" ng-show="isInvalid(log.email)">Enter valid email</div>
    </div>
    <div class="form-group  login-form" ng-class="{'has-error' : isInvalid(log.password) ,'has-success' : isValid(log.password)}">
        <input type="password" class="form-control" name="password" ng-model="user.password" required placeholder="Password">
        <div class="alert alert-danger" role="alert" ng-show="isInvalid(log.password)">This Feild is required</div>
    </div>
    <div class="form-group" style="text-align:center;">
        <input type="submit" class="logbnt" value="LOGIN" ng-disabled="! log.$valid" data-dismiss='modal'/>
    </div>
</form>

angular:

    $scope.login = function(){
    $http.post("www.example.com/login",$scope.user).then(function(res){
        localStorage.setItem("token",res.data.token);
        //how i close the modal ???
    });
}

//here create the modal
$scope.openlog = function () {
        $scope.$modalInstance = $uibModal.open({
        templateUrl:"login.html",
    });
}

那我的代码,我怎么关闭$ http结果模式?

1 个答案:

答案 0 :(得分:1)

你可以这样做,

 $scope.login = function(){
       $http.post("www.example.com/login",$scope.user).then(function(res){
        localStorage.setItem("token",res.data.token);
        $modalInstance.dismiss('cancel');
      });
    };