Switching from partial to script without reloading the Angular application

Asked

Viewed 38 times

0

Hello, I was doing some tests. And in case I want to make a conditional for a single send button to a Partial passing a parameter, or not. And I made a button calling this function: Controller

$scope.continuar = function(){
    $http.get('http://localhost:8080/api/getbyemail/[email protected]')
        .success(function(retorno) {
            console.log(retorno);
            $scope.infos = retorno;
            if (retorno.usuarioId){
                console.log("Vai passar COM o parametro");
                window.location.href = "pagina/usuarioId";
            } else {
                console.log("Vai passar SEM o parametro");
                window.location.href = "pagina";
            }
        })
        .error(function(erro) {
            console.log(erro);
        });
    };

It worked, he passed, BUT, he recharged my application, and my intention is really to use the SPA, both partials are part of the same application. I didn’t want to recharge it.

Is there any way to do this?

Thank you.

1 answer

0


I was able to find the answer :)

instead of using javascript code

 window.location.href = "pagina/usuarioId";

Now use:

$location.path("pagina/" + usuarioId);

and he changes only the view :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.