2
I have a Java/Jersey service that returns a Boolean pro Angularjs. In my controller, I take the value of the return of the Promise, but it returns me an Object. In other cases, such as a return of an User entity, for example, works well, because I take the attributes of the returned object. Now when only a Boolean returns, how do I recover the value?
Below is an example I’m using:
Java service:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/verificaEmail")
public Boolean verificarEmail(String email){
    SimpleEntityManager simpleEntityManager = new SimpleEntityManager(persistenceUnitName);
    IUsuarioBusiness usuarioB = new UsuarioBusiness(simpleEntityManager);
    Boolean result = usuarioB.verificaEmail(email);
    return result;
}
Controller Angularjs:
this.cadastrarUsuario = function() {
  var usuario = {
    email: this.usuarioLogin.email,
    senha: this.usuarioLogin.senha,
    nome: this.usuarioLogin.nome
  }
  var verificaEmail = VerificaEmail.email(usuario.email);
  verificaEmail.$promise.then( 
    function success(result)
    {
      if (result) {
        $scope.erro = true;
        $scope.mensagemErro = "Email já existe!";
        $scope.mostraMensagem = true;
        $scope.setClasseErro();
      }
    })};
Service:
var servicoLogin = angular.module('servicoLogin', ['ngResource']);
servicoLogin.factory('VerificaEmail', ['$resource',
  function($resource){
    return $resource('http://localhost:8081/GameService/webserver/usuario/verificaEmail', {}, {
      email: {method:'POST'}
    });
  }]);I’m only asking for help because I’ve already broken my head and I can’t solve this problem that seems to be simple.
Post the json being returned
– Jéf Bueno
How is this function
VerificaEmail.email(usuario.email)? She uses the$httpto make the request?– Leandro Godoy Rosa
@Leandrogodoyrosa, I am using the angular-Resource. I put the function in the body of the question.
– Eduardo Martins
@jbueno the return is a json with only "false" or "true"
– Eduardo Martins
If
resultis always"true"or"false", theif(result)is always true (because you are dealing with strings in JS).– bfavaretto