로그인 페이지에서 잘못된 자격 증명 (로그인/패스)을 입력하면 오류 메시지가 빨간색으로 표시됩니다. login.html에서ng-show attribut가 html 블록 깜박임 (초보자)
:
<div class="alert alert-danger" ng-show="authenticationError"
translate="login.messages.error.authentication">
<strong></strong>
</div>
내가 ng-show="true"
가 명시 적으로, 메시지가 화면에 지속적으로 설정하면, (다행히도). ng-show
이 변수가 참이 후, 에러 메시지가 표시로 설정하지만, 화면에 1 초 왼쪽 후 사라지게된다
(authenticationError
변수) 동적 인 경우 문제가 온다. 장면 (컨트롤러 + 서비스) 뒤에
:
login.controller.js :
$scope.login = function() {
// event.preventDefault();
Auth.login({
username: $scope.username,
password: $scope.password,
rememberMe: $scope.rememberMe
}).then(function() {
$scope.authenticationError = false;
// if()
if ($rootScope.previousStateName === 'register') {
$state.go('home');
} else {
$rootScope.back();
}
}).catch(function() {
$scope.authenticationError = true;
});
};
auth.service.js :
angular.module('tessicommunicationApp')
.factory('Auth', function Auth($rootScope, $state, $q, $translate, Principal, AuthServerProvider, Account, Register, Activate, Password, PasswordResetInit, PasswordResetFinish) {
return {
login: function (credentials, callback) {
var cb = callback || angular.noop;
var deferred = $q.defer();
console.log("login ...");
AuthServerProvider.login(credentials).then(function (data) {
// retrieve the logged account information
Principal.identity(true).then(function(account) {
// After the login the language will be changed to
// the language selected by the user during his registration
$translate.use(account.langKey).then(function(){
$translate.refresh();
});
deferred.resolve(data);
});
return cb();
}).catch(function (err) {
this.logout();
deferred.reject(err);
console.log("erreur login !");
return cb(err);
}.bind(this));
return deferred.promise;
},
인증. session.service.js :
angular
.module('tessicommunicationApp')
.factory(
'AuthServerProvider',
function loginService($http, localStorageService, $window, $state, $cookies) {
return {
login : function(credentials) {
var data = 'j_username='
+ encodeURIComponent(credentials.username)
+ '&j_password='
+ encodeURIComponent(credentials.password)
+ '&remember-me=' + credentials.rememberMe
+ '&submit=Login';
return $http
.post(
'api/authentication',
data,
{
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(response) {
return response;
});
},
더 많은 코드가 필요한 경우 알려주십시오.
컨텍스트이다 :이 티켓을 디버깅해야
1).
2)이 웹 응용 프로그램의 무엇이든 (특히 프론트 엔드 부분)
3) 나는 거의 AngularJS와의 어떠한 지식 (단지 이론 조금이 없다)을 코딩하지 않았다.
난 당신이 내 첫 번째 티켓을 해결하는 데 도움이됩니다 바랍니다 :.) *
괄호에는 잘못되었습니다. 질문에 괜찮습니다. 변수 변경을 보았을 때 모두 유효합니다 (유효하지 않은 로그인/통과 또는 유효하면 false). 내가 코드 새로 고침/아약스, 직접 코드가 아닌 어딘가 부작용이 용의자. –
그래서'.bind'가 존재한다고 말하고 있습니다; 이것은 .... (function() {}). bind()' – Dalorzo
예와 같이'function().} .bind()'와 같은 방식으로 작동합니다. 내가 말하는 것처럼 브라우저 콘솔에 구문 오류가 있습니다. 내가 볼 수있는 것은, 오류 메시지가 매우 짧은 시간을 표시 할 때 페이지가 로딩을 계속할 때 (진행 막대가 보임) 내용을 다시 새로 고친다 고 가정합니다. 오류 메시지가 없어집니다. –