When a state is clicked at first, the div that owns the "ui-view" attribute is replaced with the "template" of that state. However, when I click the same state again, its controller does not reloaded. How can I make this controller to load again?
For example, suppose I have the following navigation menu:
<nav>
<a ui-sref="state1">State 1</a>
<a ui-sref="state2">State 2</a>
</nav>
My "ui-view" content is as follows:
<div ui-view></div>
My states are described as below. When I click the "State1" on the navigation menu, I expect to observe the text "Ctrl 1 loaded"
on the developer console
. If it's first time, then I observe that text. However, when I re-click the same link, the controller is not loaded again that is I couldn't see the text "Ctrl 1 loaded"
displayed on the console twice.
myApp.config(function ($stateProvider, $urlRouterProvider){
$stateProvider.state("state1", {
url: "#",
template: "<p>State 1</p>",
controller: "Ctrl1"
}).state("state2", {
url: "#",
template: "<p>State 2</p>",
controller: "Ctrl2"
});
});
Why? Do you have any idea?
Here is the JSFiddle of this question.