0
Sorry to come back in almost the same topic, but now when I use a Parse.Query to get my data in service.js, I’m not able to pass JSON with content to the controller(app.js), follows below excerpt of the codes. service js.
var example = angular.module('starter')
example.service('EquipeService', ['$http', function($http) {
  var aDadosEscalacao = {};
  this.getEscalacao = function(params) {
            Parse.initialize('APPLICATION_ID', 'JAVASCRIPT_KEY'); 
            Parse.serverURL = 'https://parseapi.back4app.com';
            var EscalacaoObject = Parse.Object.extend("Escalacao");
            var Escalacaoquery = new Parse.Query(EscalacaoObject);
            if(params !== undefined) {
              if(params.idPeople !== undefined) {
                  Escalacaoquery.equalTo("jogador", params.idPeople);
              }        
              if(params.idPosicao !== undefined) {
                  Escalacaoquery.equalTo("jogoude", params.idPosicao);
              }        
              if(params.idEquipe !== undefined) {
                  Escalacaoquery.equalTo("time", params.idEquipe);
              }        
              if(params.idEvento !== undefined) {
                  Escalacaoquery.equalTo("pelada", params.idEvento);
              }        
            }
            Escalacaoquery.find({
                    success: function(results) {
                        //console.log("Em Escalacao, achamos " + results.length + " jogadores escalados!");
                        for (var i = 0; i < results.length; i++) {
                            var object = results[i];
                            var jogadortxtJSON = JSON.stringify(object.get("jogador"));
                            var jogoudetxtJSON = JSON.stringify(object.get("jogoude"));
                            var timetxtJSON = JSON.stringify(object.get("time"));
                            var peladatxtJSON = JSON.stringify(object.get("pelada"));
                            var golstxtJSON = JSON.stringify(object.get("Gols"));
                            var faltastxtJSON = JSON.stringify(object.get("faltas"));
                            var crtamarelotxtJSON = JSON.stringify(object.get("cartao_amarelo"));
                            var crtvermelhotxtJSON = JSON.stringify(object.get("cartao_vermelho"));
                            var ptoscraquetxtJSON = JSON.stringify(object.get("PontuacaoCraque"));
                            var ptosdestaquetxtJSON = JSON.stringify(object.get("PontuacaoDestaque"));
                            var ptosmastertxtJSON = JSON.stringify(object.get("PontuacaoMaster"));
                            var ptosgoleirotxtJSON = JSON.stringify(object.get("pontuacaogoleiro"));
                            idtxtjogador = JSON.parse(jogadortxtJSON);
                            idjogador = idtxtjogador.objectId                //id do jogador
                            idtxtjogoude = JSON.parse(jogoudetxtJSON); 
                            idjogoude = idtxtjogoude.objectId                //id jodou de ...
                            idtxttime    = JSON.parse(timetxtJSON);  
                            idtime = idtxttime.objectId                      //id da Equipe/Time
                            idtxtpelada  = JSON.parse(peladatxtJSON); 
                            idpelada  = idtxtpelada.objectId                 //id da pelada/evento. 
                            ngolsjogador = JSON.parse(golstxtJSON);          //Quantidade de Gols do Jogador
                            faltastxtJSON = JSON.parse(faltastxtJSON);       //Quantidade de Faltas do Jogador
                            ncrtamarelos = JSON.parse(crtamarelotxtJSON);    //Quantidade de Cartões Amarelos
                            ncrtvermelhos = JSON.parse(crtvermelhotxtJSON);  //Quantidade de Cartões Vermelhos
                            nptoscraque = JSON.parse(ptoscraquetxtJSON);     //Quantidade de Pontos para eleição do Craque
                            nptosdestaque = JSON.parse(ptosdestaquetxtJSON); //Quantidade de Pontos para eleição Destaque
                            nptosmaster = JSON.parse(ptosmastertxtJSON);     //Quantidade de Pontos para eleição Master
                            nptosgoleiro = JSON.parse(ptosgoleirotxtJSON);   //Quantidade de Pontos para eleição Goleiro
                            aDadosEscalacao = { "idjogador": idjogador, 
                                                "idtime": idtime,
                                                "idjogoude": idjogoude,
                                                "idpelada": idpelada,
                                                "gols": ngolsjogador,
                                                "faltas": faltastxtJSON,
                                                "cartao_amarelo": ncrtamarelos,
                                                "cartao_vermelho": ncrtvermelhos,
                                                "pontuacaocraque": nptoscraque,
                                                "pontuacaodestaque": nptosdestaque,
                                                "pontuacaomaster": nptosmaster,
                                                "pontuacaogoleiro": nptosgoleiro };
                        }
                        return aDadosEscalacao
                    },
                      error: function(error) {
                          alert("Error: " + error.code + " " + error.message);
                      }
            });
  }
}])            
excerpt from controller(app.js)
example.controller('equipecontrol', ['EquipeService','$scope', function( EquipeService,$scope) {      
    equipes =  { "nomejogador": '',
                 "posioriginal":'',
                 "nomedotime": '',
                 "jogoude": ''
                };
listaobjEquipes = EquipeService.getEscalacao(); <-- IS RETURNING OBJECT VÁZIO
I don’t know if this is the point where I’m putting Return, but the truth is that JSON is coming up empty in the controller, what procedure should I adopt to get JSON with content into the controller?
Possible duplicate of How to pass JSON Object content to a controller
– user28595
Please do not use citation formatting unnecessarily.
– user28595
Does anyone have any idea how I can solve this case?
– Ita
@leandrooriente, Continuing my tests, I found that when I use find() the object returns to empty for the controller, has some idea of solution in this context?
– Ita
Someone can shed a light?
– Ita