3
I have the following problem, I have more than one state of navigation in the angular that uses the same controller, so:
.state('app.estado-navegacao-1', {
url: "/estado-navegacao-1",
views: {
'menuContent': {
templateUrl: "templates/estado1.html",
controller: 'EstadoNavegacaoCtrl',
controllerAs: 'estado'
}
}
})
.state('app.estado-navegacao-2', {
url: "/estado-navegacao-1",
views: {
'menuContent': {
templateUrl: "templates/estado2.html",
controller: 'EstadoNavegacaoCtrl',
controllerAs: 'estado'
}
}
})
Well, I would like you to "execute" that state, enter the controller, execute the normal methods and a Function that varies according to the chosen browsing state.
My controller looks something like this:
angular.module('controllers.estadonavegacao', [])
.controller('EstadoNavegacao', EstadoNavegacao);
function EstadoNavegacao() {
var vm = this;
vm.init = init;
vm.funcao = funcao;
vm.funcao2 = funcao2;
//Executa Normal nas duas chamadas
init();
function init() {
};
function funcao() {
//Quero executar após o estado de navegação 1
};
function funcao2() {
//Quero executar após o estado de navegação 2
};
};
Does anyone have any idea how to make it work that way?
In addition to the two answers, for the sake of code organization and maintenance, I suggest you do not use the same controller for more than one view. With simple functions no problem, but you can have good headaches when you have something more complex.
– celsomtrindade
Yes, I had thought about it, but I use the controller to generate Charts, and each Function is a different Chart, but from the same controller. What changes is basically the query and the display form, making multiple extra controllers would be a much bigger coding job. I separated so: Shopping, Financial, etc...
– Geferson