如何在angularjs中提交后关闭modal

vlurs2pr  于 10个月前  发布在  Angular
关注(0)|答案(2)|浏览(127)

我知道这个问题有很多结果,但没有一个给予答案。
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结果中关闭模态的?

bqujaahr

bqujaahr1#

你能做到的

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

字符串

yr9zkbsy

yr9zkbsy2#

你只需要添加这行代码。
angular.element('#modelName').modal('hide');

相关问题