当我登录管理部分时。我收到的问题有{{vm.error}}
。
<div class="col-md-6 col-md-offset-3 bg-success">
<h2>Admin Login</h2>
<div ng-show="vm.error" class="alert alert-danger">{{vm.error}}</div>
<form name="form" ng-submit="vm.admin()" role="form" novalidate>
<div class="form-group" ng-class="{ 'has-error': form.username.$dirty && form.username.$error.required }">
<label for="username">Username</label>
<input type="text" name="username" id="username" class="form-control" ng-model="vm.username" required />
<span ng-show="form.username.$dirty && form.username.$error.required" class="help-block">Username is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.password.$dirty && form.password.$error.required }">
<label for="password">Password</label>
<input type="password" name="password" id="password" class="form-control" ng-model="vm.password" required />
<span ng-show="form.password.$dirty && form.password.$error.required" class="help-block">Password is required</span>
</div>
<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" class="btn btn-danger">Login</button>
<img ng-if="vm.dataLoading" src="" />
<a href="#/register" class="btn btn-danger">Register</a>
<a href="#/forgetpassword"> Forget Password </a>
</div>
</form>
</div>
&#13;
控制器管理员
(function () {
'use strict';
angular.module('app').controller('AdminController', AdminController);
AdminController.$inject = ['$location', 'AuthenticationService', 'FlashService'];
function AdminController($location, AuthenticationService, FlashService) {
var vm = this;
vm.admin = admin;
(function initController() {
// reset login status
AuthenticationService.ClearCredentials();
})();
function admin()
{
vm.dataLoading = true;
AuthenticationService.Login(vm.username, vm.password, function (response) {
if (response.success) {
AuthenticationService.SetCredentials(vm.username, vm.password);
$location.path('/');
} else {
FlashService.Error(response.message);
vm.dataLoading = false;
}
});
};
}
})();
答案 0 :(得分:0)
屏幕上显示{{vm.error}}
,因为角色对此一无所知。您的控制器仅设置vm.admin
,因此vm.error
未知。
您似乎将错误设置为FlashService
。你需要以某种方式从那里得到错误 - 它不会为你神奇地把它变成vm.error。
您似乎正在尝试复制此处显示的登录方法:https://github.com/cornflourblue/angular-registration-login-example
请注意,他们的Flash消息位于主布局中(在所有视图中共享),而不是登录页面的一部分。 (https://github.com/cornflourblue/angular-registration-login-example/blob/master/index.html#L14)