我正在处理已由其他人制作的登录脚本。我的目的实际上是整合使用ng-option
而不是input
。从示例中可以看出,这很有效。但是当我登录时,我看不到用户的数据。为什么呢?
完整代码:http://plnkr.co/edit/ImsqhVFVanCp5OXNisrA?p=preview
Controllers.js:
angular.module('Authentication')
.controller('LoginController',
['$scope', '$rootScope', '$location', 'AuthenticationService',
function ($scope, $rootScope, $location, AuthenticationService) {
// reset login status
AuthenticationService.ClearCredentials();
$scope.users = [
{"username": "test", "number": "13242342"},
{"username": "2", "number": "00000000"},
{"username": "3", "number": "0483184"},
];
$scope.login = function () {
$scope.dataLoading = true;
AuthenticationService.Login($scope.username, $scope.password, function(response) {
if(response.success) {
AuthenticationService.SetCredentials($scope.username, $scope.password);
$location.path('/');
} else {
$scope.error = response.message;
$scope.dataLoading = false;
}
});
};
}]);
答案 0 :(得分:1)
在您的身份验证服务中,您可以像这样设置用户的凭据:
$rootScope.globals = {
currentUser: {
username: username,
authdata: authdata
}
};
因此,在您看来,您需要将{{user.username}}
更改为{{globals.currentUser.username}}
。