每当我单击“提交”按钮时,什么都没有发生,当前我要做的就是打印出用户名和密码以测试其中的绑定。
而且我能够与控制器对话并打印出我在控制器中发出的硬编码消息,似乎ng-click不会触发该方法。
任何帮助都会很棒,
感谢:D
<section id="register-view" class="mainbar">
<section class="matter">
<div class="container">
<div class="row">
<label>{{vm.message}}</label>
<form class="register-form">
<label name="username_label"> Username: </label>
<input type="text" name="username" ng-model="vm.userDetails.username"/>
<br/>
<label name="password_label"> Password: </label>
<input type="text" name="password" ng-model="vm.userDetails.password"/>
<br/>
<button type="submit" class="btn btn-default" ng-click="vm.submitUserDetails()">Submit</button>
</form>
</div>
</div>
</section>
</section>
和控制器类
(function () {
'use strict';
angular
.module('app.register')
.controller('RegisterController', RegisterController);
RegisterController.$inject = ['$q', 'dataservice', 'logger'];
/* @ngInject */
function RegisterController($q, dataservice, logger) {
var vm = this;
vm.message = 'baass';
vm.userDetails = {
username: '',
password: ''
}
function activate() {
var promises = [submitUserDetails()];
return $q.all(promises).then(function () {
logger.info('Activated Dashboard View');
});
}
function submitUserDetails() {
console.log('Username: ' + vm.userDetails.username);
console.log('Password: ' + vm.userDetails.password);
}
}
})();
最佳答案
您仅需定义submitUserDetails
的功能,就需要在控制器上下文中添加submitUserDetails
使其在视图中可用。您应该将其引用绑定到vm.submitUserDetails
vm.submitUserDetails = submitUserDetails;