我的 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"> </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 的更多信息为
关于AngularJS Controller 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44131993/