executar um serviço após uma chamada ajax no AngularJS
Preciso salvar dados em uma fábrica de serviços após uma chamada ajax. Tudo funciona sem location.href. Mas não funciona quando coloco o código de linha $ window.location.href. Este é o código:
scope.res = function(id){
factoryService.getLista(id,"en-US","")
.then (function(response){commonVarService.setA(response.A);
commonVarService.setB(response.B);
commonVarService.setC(response.C);
$window.location.href="./menu/menu.html";
})
.catch(function(err) {console.log(err)});
};
Onde factoryService permite fazer uma chamada ajax, enquanto commonVarService permite memorizar dados em variáveis de serviço. Se não houver $ window.location.href = "" tudo funcionará, mas quando houver $ window.location.href, o aplicativo será redirecionado na nova página sem memorizar a variável. onde está o meu erro? Existe alguma boa solução? Desde já, obrigado.
o código commonVarService é este:
angular.module ('common_variable', []) .service ('commonVarService', function () {
/*a*/
this.getA = function(){
return this._a;
}
this.setA = function(a){
return this._a=a;
}
/*b*/
this.getB = function(){
return this._b;
}
this.setB = function(b){
return this._b = b;
}
/*c*/
this.getC = function(){
return this._c;
}
this.setC = function(c){
return this._c = c;
}
});
Também tentei colocar apenas a string como parâmetro:
commonVarService.setA ("A"); commonVarService.setB ("B"); commonVarService.setC ("C")
mas quando estou no novo page.html do link href, as variáveis A, B, C são indefinidas ... não sei ..
Obrigado antecipadamente!