I'm using ng-route to develop a single page application with angularjs + laravel. I'm having a problem with the swap view with ng-click and controller. I have a button in a view, and I would like it to be clicked by redirecting it to another view, taking an info (id).
This is my angular route file. I want to redirect from the Manage Employees page to the New Contributor page.
angular.module('registrosGerais')
.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/index.html',
controller: ''
})
.when('/colaboradores', {
templateUrl: 'views/colaboradores/gerenciarcolaboradores.html',
controller: 'colaboradoresController'
})
.when('/colaboradores/novocolaborador', {
templateUrl: 'views/colaboradores/novocolaborador.html',
controller: 'colaboradoresController'
})
.otherwise({
redirectTo: '/colaboradores'
});
});
This is the button that must be clicked to redirect the new view.
<button id="btn-add" class="btn btn-primary btn-xs"
ng-click="toggle('add', 0, '/#/colaboradores/novocolaborador')">Novo Colaborador</button>
This is my controller.
app.controller('colaboradoresController', function($scope, $http, API_URL) {
$http.get(API_URL + "colaboradores")
.success(function(response) {
$scope.tbcolaborador = response;
});
$scope.toggle = function(modalstate, id, $location) {
$scope.modalstate = modalstate;
$location.path('/#/colaboradores/novocolaborador');
}
The exchange of view should be done by taking an information (0 case to add a new one) and the id if it is an existing collaborator. Thanks in advance for your help.