表单 - HTML
电子邮件地址: 电子邮件地址字段是必填项 太长 无效的邮件地址 密码: 密码字段是必需的 登录登录控制器 - Angular JS
(function () {
'use strict';
angular
.module('app')
.controller('loginController', loginController);
loginController.$inject = ['ApiService', '$location', 'AuthenticationService', 'FlashService'];
function loginController(ApiService, $location, AuthenticationService, FlashService) {
var vm = this;
vm.userLogin = userLogin;
(function initController() {
// reset login status
AuthenticationService.ClearCredentials();
})();
function userLogin() {
FlashService.clearNotification();
ApiService.userLogin(vm.user).then(function (response) {
if (response.success) {
FlashService.Success(response.message);
} else {
FlashService.Error(response.message);
}
vm.user.$setPristine();
});
}
}
})();
答案 0 :(得分:0)
我认为您还必须设置vm.user = {};
和vm.user.$setPristine(true);
。
loginController.$inject = ['ApiService', '$location', 'AuthenticationService', 'FlashService'];
function loginController(ApiService, $location, AuthenticationService, FlashService) {
var vm = this;
vm.userLogin = userLogin;
(function initController() {
// reset login status
AuthenticationService.ClearCredentials();
})();
function userLogin() {
FlashService.clearNotification();
ApiService.userLogin(vm.user).then(function (response) {
if (response.success) {
FlashService.Success(response.message);
} else {
FlashService.Error(response.message);
}
vm.user = {};
vm.user.$setPristine(true);
});
}
}