我有以下代码,我无法触发 - ng-submit或ng-click,除了登录按钮上的本地onclick功能。如果您知道好的解决方案或能够确定问题,请让我知道:
<form ng-submit = "login.submitLoginForm(login.user)" novalidate>
<p>
<input class="username-email" type="email" name="username" value="" placeholder="Your Email"
ng-model="login.user.userName">
</p>
<p>
<input class="password" type="password" name="password" value="" placeholder="Password"
ng-model="login.user.pwd">
</p>
<div class="checkbox">
<label>
<input type="checkbox" value="">Remember me</label>
</div>
<p>
<button class="login" type="submit" name="Login" value="Login">Login</button>
</p>
</form>
vm.submitLoginForm = submitLoginForm;
function submitLoginForm(user) {
// submitLoginForm...
console.log("UserName..form.." + user.UserName + 'pwd..' + user.pwd);
if(user.userName != '' || user.userName != 'undefined'){
vm.user.userName = user.userName;
console.log("UserName..form.." + user.userName + vm.user.userName);
ServiceFactory.setUserName(vm.user.userName);
}
if(user.pwd != '' || user.pwd != 'undefined'){
vm.user.pwd = user.pwd;
console.log("UserName..pwd.." + user.pwd + vm.user.pwd);
ServiceFactory.setPwd(vm.user.pwd);
}
initialize();
};
答案 0 :(得分:0)
'use strict';
angular
.module('app', [])
.controller('LoginCtrlr', LoginCtrlr);
function LoginCtrlr() {
var vm = this;
vm.user = {
userName: '',
pwd: ''
};
vm.submitLoginForm = function submitLoginForm(user) {
// submitLoginForm...
console.log("UserName..form.." + user.userName + ' vm userName: ' + vm.userName);
if (user.userName != '' || user.userName != 'undefined') {
vm.userName = user.userName;
console.log("UserName..form.." + user.userName + ' vm. userName: ' + vm.userName);
}
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<section class="container" ng-controller="LoginCtrlr as login">
<div>
<p class="or">Or</p>
<p class="login">your email</p>
<form novalidate>
<p>
<input class="username-email" type="email" name="username" value="" placeholder="Your Email" ng-model="login.user.userName">
</p>
<p>
<input class="password" type="password" name="password" value="" placeholder="Password" ng-model="login.user.pwd">
</p>
<div class="checkbox">
<label>
<input type="checkbox" value="">Remember me</label>
</div>
<p>
<button class="login" type="submit" name="Login" value="Login" ng-click="login.submitLoginForm(login.user)">Login</button>
</p>
<div>{{ login.message }}</div>
</form>
</div>
<p class="note-text-center-xs">By continuing, you accept the terms of Use and Privacy Policy</p>
<div class="login-help-center-xs">
<p><a href="#">Forgot your password?</a>
</p>
</div>
<p class="no-account" onclick="#">You Don't have an account yet? Sign up</p>
</a>
</section>
</div>
&#13;
我尝试创建剪切的完整代码。删除依赖模块,因为并非所有人都可以通过代码剪切来访问。
我改变了什么:
当您将对象分配到模型中时,需要调用控制器,因为您将所有控制器的方法和属性自定义为自身,而不是使用$ scope。例如:
<input class="username-email" type="email" name="username" value="" placeholder="Your Email" ng-model="login.user.userName">