1
Well, it’s the first time I’ve ever done anything with Angular.js and I’m picking up a bit to create a message of "Incorrect Login and Passwords" with the same.
I have a method in a file . js that is below:
angular.module('myApp',[])
.controller('loginController', function($scope){
$scope.displayLoginError = (url.indexOf("error") >= 0);
});
Logo on my . jsp did the Angular and File import with my method:
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/angular.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/pages/login.js"></script>
Nesta mesma pagina tenho um form de login com a DIV que faz a verificação
<div ng-app="myApp">
<div ng-controller="loginController">
<div ng-class="{{'': displayLoginError == true, 'none': displayLoginError == false}}">
<span class="entypo-attention"></span> <strong>Erro!</strong> Login
ou Senha Incorretos!
</div>
</div>
<form class="form-signin" method="post"
action="j_spring_security_check">
<div class="input-group">
<span class="input-group-addon entypo-user"></span> <input
name="j_username" id="j_username" type="text" class="form-control"
placeholder="Usuario">
</div>
<br>
<div class="input-group">
<span style="padding: 0 14px;" class="input-group-addon entypo-lock"></span>
<input name="j_password" id="j_password" type="password"
class="form-control" placeholder="Senha">
</div>
<button type="submit"
class="btn btn-lg btn-fltees btn-primary btn-block">Entrar</button>
<a href="<c:url value="register"/>"
class="btn btn-lg btn-fltees btn-primary btn-block">Crie uma nova
Agência!</a>
</form>
</div>
Well, I’m using Spring Security. Just when the authentication fails a parameter and added in the URL (...?error=403), so my javascript method can go into action and display or not the message in my form.
The problem that such error message is displayed:
Does anyone know how I can solve?
EDITION
The method that performs the URL check. In the url variable the value is right.
angular.module('myApp',[])
.controller('loginController', function($scope, $location){
var url = "" + $location.$$absUrl;
$scope.displayLoginError = (url.indexOf("error") >= 0);
});
This is the section where you will check for authentication error and will present the:
<div ng-controller="loginController">
<div class="alert alert-danger" ng-class="{'': displayLoginError == true, 'none': displayLoginError == false}">
<span class="entypo-attention"></span> <strong>Erro!</strong> Login ou Senha Incorretos!
</div>
</div>
But logica doesn’t seem to work and no more bugs in the firebug console
You can’t see the complete error by this URL that you passed. It has to post the error message?
– gabrielhof
According to the codes you posted, the attribute
ng-app="myApp"
is set twice?<html lang="pt-BR" id="ng-app" ng-app="myApp">
and<div ng-app="myApp">
. Other than that lastdiv
does not solve the problem? Anyway, post the complete error.– gabrielhof
Hello @gabrielhof, well I removed the
<div ng-app="myApp">
and it didn’t work. I edited the question with the completed bug firebug reports to me. Thank you– João Manolo
It seems to be a syntax error. Why did you put two keys (
{{
) in ngClass? (ng-class="{{'': displayLoginError == true, 'none': displayLoginError == false}}"
) Try to put only one on each side.– danguilherme
It’s true @Danguilherme. I think the directive
ngClass
do expects something similar to the format JSON: https://docs.angularjs.org/aping/directive/ngClass– gabrielhof
In fact, it’s a JSON object that she really expects, because she will treat it as a normal javascript object internally.
– danguilherme
Hi guys, I ended up leaving trip and could not test the solution offered by our friend @Danguilherme. But unfortunately it did not work. The error message this time was another. It is accusing that the url. I ended up taking this example in a blog, it seems that is not correct the way used by the writer of the same. Does anyone have any suggestions how can I get the value passed in the URL? I updated the question with the recent stacktrace. Thank you all.
– João Manolo
In the login.js file, on line 3, you are referencing a variable
url
which was not previously declared. You can post the code of this file to confirm?– danguilherme
Hi @Danguilherme, I fixed the variable problem url, masw now seems that logic is not hitting. I edited the question again explaining what happens. Obliged by the help.
– João Manolo
You’re using
ng-class
to hide the message? I don’t think it will work, remove thisng-class
and tries to useng-show="displayLoginError"
.– gabrielhof
Yes that was the goal @gabrielhof. It worked perfectly with the ng-show. Thanks for your help. I’m going to grab some links to learn more about Angular.js. Have any suggestions you’d like to share?
– João Manolo
Cool :) ! Just remember to post an answer explaining what you do to work.
– gabrielhof
Oops, I’ve answered it the way it worked @gabrielhof
– João Manolo