How to redirect view in a controller with AngularJS

1

I have a department query page and I have the button in it. This page is a view that has been defined as a route and is called within my index.html.

I would like to know how it is possible to click the register button, change the view that I am to the one that I will use.

Do I have to use any specific angled service?

These are my routes:

$routeProvider
    .when("/cadastro/produtos", {
        templateUrl: 'view/consultaDeProdutos.html',
        controller: 'productRegisterController as vm'
    })

    .when("/cadastro/categorias", {
        templateUrl: 'view/consultaDeCategorias.html',
        controller: 'categoryRegisterController as vm'
    })

    .when("/cadastro/departamentos", {
        templateUrl: 'view/consultaDeDepartamentos.html',
        controller: 'departmentRegisterController as vm'
    })

    .when("/cadastro/departamentos/salvar", {
        templateUrl: 'view/cadastroDeDepartamentos.html',
        controller: 'departmentRegisterController as vm'
    })

I want the route / registration / departments go to / register / departments / save

via a button

    
asked by anonymous 16.07.2017 / 02:03

1 answer

0

You need to use the $location service to change routes / views.

app.controller('departmentRegisterController', ['$location', '$scope', function ($location,$scope) {

    var vm = this;

    vm.Cadastrar = function() {
        $location.path('/cadastro/departamentos/salvar');
    }

}]);

Then the button you can use like this:

<button ng-click="vm.Cadastrar()">Cadastrar</button>

In the controller of the registration screen (in your case it is the same controller), you can create another method to return to the list of departments:

vm.ExibirListaDeDepartamentos = function() {
    $location.path('/cadastro/departamentos');
}

And create a Cancel or Back button like this:

<button ng-click="vm.ExibirListaDeDepartamentos()">Cancelar</button>
    
16.07.2017 / 02:46