简体   繁体   English

无法从Angular js的html页面中将用户名和密码传递给控制器

[英]unable to pass username and password to controller from the html page in angular js

i have two fields username and password that i want to get in the angular js controller to verify the login. 我有两个字段用户名和密码,我想在angular js控制器中获取以验证登录名。 but in the controller im not able to get it after filling the username and password and submitting the button 但是在控制器中,我在填写用户名和密码并提交按钮后无法获取它

     <form class="form-signin" action="" method="post">
                        <span id="reauth-email" class="reauth-email"></span>
                        <input type="text" ng-model="username" id="Username" name="Username" class="form-control" placeholder="Email address" required autofocus>
                        <input type="password" ng-model="password" id="password" name="password" class="form-control" placeholder="Password" required style="margin-top:10px">
                        <div id="remember" class="checkbox">
                            <label>
                                <input type="checkbox" value="remember-me"> Remember me
                            </label>
                        </div>
                        <input type="hidden" name="" value="" />
                        <input class="btn btn-lg btn-primary btn-block btn-signin"  type="button" value="{{btntext}}" ng-click="login()" >
                    </form>

angular js 角js

var app = angular.module('homeapp', []);
app.controller('HomeController', function($scope, $http) {
  $scope.username = '';
  alert($scope.username);
  $scope.btntext="Login";
  $scope.login=function () {
  $http.get("/account/loginverify")
  .then(function(response) {
    $scope.myWelcome = response.data;
    if(response.data=="1"){
      window.location.href='home.html'
    } 
    else  {
      alert("Invalid username  or password...!!!")
    }
  });
}
});

You need to bind your controller to the HTML template using ngController directive. 您需要使用ngController指令将控制器绑定到HTML模板。 See the following example: 请参见以下示例:

 var app = angular.module('homeapp', []); app.controller('HomeController', function($scope, $http) { $scope.username = ''; $scope.btntext = "Login"; $scope.login = function() { console.log($scope.username, $scope.password); //$http.get("/account/loginverify") // .then(function(response) { // $scope.myWelcome = response.data; // if (response.data == "1") { // window.location.href = 'home.html' // } else { // alert("Invalid username or password...!!!") // } // }); } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <form class="form-signin" action="" method="post" ng-app="homeapp" ng-controller="HomeController"> <span id="reauth-email" class="reauth-email"></span> <input type="text" ng-model="username" id="Username" name="Username" class="form-control" placeholder="Email address" required autofocus> <input type="password" ng-model="password" id="password" name="password" class="form-control" placeholder="Password" required style="margin-top:10px"> <div id="remember" class="checkbox"> <label> <input type="checkbox" value="remember-me"> Remember me </label> </div> <input type="hidden" name="" value="" /> <input class="btn btn-lg btn-primary btn-block btn-signin" type="button" value="{{btntext}}" ng-click="login()"> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 angular js:无法将值从控制器传递到包含页面的html - angular js: Not able to pass value from controller to html of an included page 如何使用 javascript 将用户名和密码从页面传递到另一个页面 - how to pass username and password from page to another using javascript Angular JS父控制器无法将单独的变量传递给子控制器 - Angular JS parent controller unable to pass alone variables to child controller 将数组变量从控制器传递给 Angular 中的 html - Pass array variable from controller to html in Angular 在控制器中传递html字符串并放入.html(角度js) - Pass html string in controller and put into .html (angular js) 在 UIWebView 中打开的 HTML 页面中自动填充用户名和密码 - Autofill username and password in an HTML page opening in UIWebView 在Angular Js中重新加载后,如何将javascript控制器中的复选框(选中或未选中)更新为html页面? - How to update checkbox (checked or unchecked) from javascript controller to html page after reloading in Angular Js? 在页面加载后动态地使用html注入新的角度js控制器 - Inject new angular js controller with html dynamically after page loaded 在Angular2js / Dart中将变量传递到html页面 - pass a variable to html page in Angular2js / Dart 如何将变量从html视图传递到角度控制器以按作用域访问 - How to pass variable from html view to angular controller to access by scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM