点击登录按钮

时间:2017-07-13 07:31:34

标签: angularjs

我想做这样的事情:当我填写deatils,即名称和密码并点击登录时,它应该显示详细信息我已填写文本框中的欢迎消息(以角度模式或弹出式)。它应该很简单。任何人都可以帮助我。我看过UI bootstrap模式,但我没有得到任何东西。

    <div ng-controller="logincontroller">
       <div class="container-fluid">
          <form action="" method="" class="register-form"> 
            <div class="row">      
               <div class="col-md-4 col-sm-4 col-lg-4">
                  <label for="firstName">NAME</label>
                  <input name="firstName" minlength="3" maxlength="15" required  class="form-control firstname" type="text" >    
               </div>   

            </div>

        <div class="row">
           <div class="col-md-4 col-sm-4 col-lg-4">
               <label for="password">PASSWORD</label>
               <input name="password" required class="form-control password" type="password" >             
          </div>            
        </div>
    <hr>

        <div class="row">
          <div class="col-md-6 col-sm-6 col-xs-6 col-lg-6">
             <button class="btn btn-default regbutton" ng-click="open()">Login</button>

             <div class="modal">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">Login</h4>
                      </div>

                      <div class="modal-footer">
                        <button type="button" class="btn btn-default" ng-click="cancel()">No</button>
                        <button type="button" class="btn btn-primary" ng-click="ok()">Yes</button>
                      </div>
                    </div>
                  </div>
                </div>

         </div>

      </div>    
</form>

我的login.js文件

var mymodule=angular.module("mymodule");
 mymodule.controller("logincontroller",function($scope,$modal)
  {
    var modalInstance = $modal.open({
                    backdrop:'static',
                    keyboard:false,
                    controller: function($scope, $modalInstance) {
                        $scope.cancel = function() {
                            $modalInstance.dismiss('cancel');
                        };
                        $scope.ok = function () {
                          $modalInstance.close();
                        };
                    }
                });
  })

我收到这样的错误

  

错误:$ injector:unpr   未知的提供商   未知提供者:$ modalProvider&lt; - $ modal&lt; - logincontroller

1 个答案:

答案 0 :(得分:0)

检查这个答案。它可能会帮助你。

var app = angular.module('angularModal', ['ngAnimate', 'ui.bootstrap']);

app.controller('ModalDemoCtrl', function ($scope, $uibModal, $log) {

$scope.open = function (size) {
    var modalInstance = $uibModal.open({
        animation: $scope.animationsEnabled,
        templateUrl: 'myModalContent.html',
        controller: 'ModalInstanceCtrl',
        size: size,
        resolve: {
            firstName: function () {
                return $scope.firstName;
            }
        }
    });
};

});

// Please note that $modalInstance represents a modal window (instance)   dependency.
// It is not the same as the $uibModal service used above.

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, firstName) {
  setTimeout(function() {
    $scope.$apply(function() {
    $scope.firstName = firstName;
  })
  }, 1);
  
  $scope.ok = function () {
    $modalInstance.close($scope.firstName);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});
<!DOCTYPE html>
<html data-ng-app="angularModal">

<head>
<link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.0.js"></script>
</head>

<body>
  <div ng-controller="ModalDemoCtrl">
    <script type="text/ng-template" id="myModalContent.html">
      <div class="modal-header">
          <h3 class="modal-title">I'm a modal!</h3>
      </div>
      <div class="modal-body">
        Welcome {{firstName}}
      </div>
      <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
      </div>
  </script>
  
  <div class="container-fluid">
          <form method="" class="register-form"> 
            <div class="row">      
               <div class="col-md-4 col-sm-4 col-lg-4">
                  <label for="firstName">NAME</label>
                  <input name="firstName" minlength="3" maxlength="15" required  class="form-control firstname" type="text" ng-model="firstName">    
               </div>   

            </div>

        <div class="row">
           <div class="col-md-4 col-sm-4 col-lg-4">
               <label for="password">PASSWORD</label>
               <input name="password" required class="form-control password" type="password" >             
          </div>            
        </div>
    <hr>

        <div class="row">
          <div class="col-md-6 col-sm-6 col-xs-6 col-lg-6">
             <button class="btn btn-default regbutton" ng-click="open()">Login</button>

         </div>

      </div>    
</form>
  </div>
  </body>

 </html>

相关问题