In my application, I have defined 2 states. One is "tickets" which matches /tickets ...
$stateProvider // defines the states of my application
.state("tickets", { // assigns properties to each state
url: "/tickets", // route
templateUrl: "modules/tickets/views/ticketsTemplate.html", // template to use
controller: "TicketsController", // controller to use
controllerAs : "tickets" // alias for the controller, for using this
});
and the other one is "tickets.buscar" which matches /tickets/:id and uses the same controller as the parent ("TicketsController") ...
.state("tickets.buscar",{
url: "/:id",
templateUrl: "modules/tickets/views/ticketsResult.html"
}
) // inherits the controller from the parent
In the controller, there is an init() function that initializes the necessary variables.
this.init = function(){
this.title = "Tickets";
this.id = $state.params.id;
if(this.id){
this.getTicket(this.id);
};
};
this.init();
Based on my understanding from the UI Router documentation, there are 3 ways to access a state:
- by using the URL (or following an external link)
- using $state.go()
- using ui-sref in the HTML
I am trying to find a way to trigger a controller reload so that regardless of how the state is accessed, the init function is executed.
I know about the { reload : true } option in $state.go() but that only addresses one of the access methods. I also looked into this other question, but the solution provided doesn't work, and the $state parameter isn't documented in UI Router's documentation.