Reputation: 569
I have noticed that, whenever a $state.go()
is applied to a state with parameter(s) in AngularJS UI-Router, a new instance of the HTML content [for that view] is created each time. Not only the HTML content, but also the controller are being created as many times as newer params are appearing on the $stateParams
after calling $state.go()
in the program later on.
How do I stop new instances of HTML content and controller to stop appearing, while still passing the params to the $stateParams
? I want to use the same controller, same scope and same HTML content for any data that $stateParams
holds. Thank you very much in advance!
Upvotes: 1
Views: 1368
Reputation: 569
YES, it is possible. Disable caching.
This is done in various ways. One of the ways would be to be disable caching while defining the states. Eg:
$stateProvider.state("home",
{
url:'/home',
cache:false,
}
Adapted from ui.router not reloading controller
Upvotes: 1