AngularJS Controller 提交表单

标签 angularjs firebase firebase-authentication angularfire

我的 Controller 有问题

 .factory('Auth', function($firebaseAuth){
  var auth = $firebaseAuth();
  return auth;
 })

.controller('authCtrl', function() {
  var authCtrl = this;

  authCtrl.user = {
    email: '',
    password: ''
  };

  console.log('hoi1');

  authCtrl.login = function (){
    console.log('hoi2');
  };
});

-

<div id="loginModal" class="modal" ng-controller="authCtrl">
<div class="modal-background"></div>
<div class="modal-content">
  <div class="modal-body">
    <form ng-submit="authCtrl.login()">
      <h1>Login</h1>
      <p id="loginError">&nbsp;</p>
      <input type="email" name="loginEmail" value="" placeholder="email" class="input" ng-model="authCtrl.user.email">
      <br>
      <input type="password" name="loginPassword" value="" placeholder="******" class="input" ng-model="password" ng-model="authCtrl.user.password">
      <br>
      <input type="submit" value="Login">
    </form>
  </div>
</div>

Controller 始终在我的体内,但我在控制台中看到 hoi1,但是当我提交表单时,我没有看到 hoi2

出了什么问题?

真诚的, 朱尔

最佳答案

改变

<div id="loginModal" class="modal" ng-controller="authCtrl"> 

<div id="loginModal" class="modal" 
ng-controller="authCtrl as authCtrl">

如果你想使用 controller this 那么你必须添加 ng-controller 作为 ng-controller="authCtrl 作为 authCtrl"

检查这个tutorial有关 Controller 的更多信息为

Working Fiddle Example

关于AngularJS Controller 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44131993/

相关文章:

javascript - 使用 UI-Router 防止后退按钮的状态更改

javascript - AngularJS - 将 typeahead 与 ngTagsInput 结合使用

javascript - 删除超过 2 小时的 Firebase 数据

javascript - Firebase auth().signInWithEmailAndPassword 使用 try-catch async-await 未捕获错误

firebase - 使用 Firebase 身份验证服务时,如何在没有现有帐户的情况下通过 Facebook/Google 登录时抛出错误

javascript - 在 ng-repeat 中使用 {{expression}} 来记录 ng-click

angularjs - angular-ui-router 中的三层嵌套路由

firebase - 如果我在 Google-Service-info.plist 中将 IS_GCM_ENABLED 键禁用为 false 会发生什么

javascript - AngularJS - Firebase - promise 错误

firebase - Flutter:Java 使用或覆盖已弃用的 API