I want the controller to not reload whenever the query parameter changes. I have tried setting reloadOnSearch as false still the controller reloads on changing the stateparam.
Here is the code I am using to achieve the results.
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller:'loginCtrl'
})
.state('layout', {
url: '/layout',
templateUrl: 'templates/layout.html',
controller:'layoutCtrl'
})
.state('main', {
url: '/main',
templateUrl: 'templates/main.html',
abstract:true,
controller:'mainCtrl'
})
.state('main.welcome', {
url: '/welcome/:id',
templateUrl: 'templates/welcome.html',
reloadOnSearch : false,
controller:'greetingCtrl'
})
For example when the state changes from /main/welcome/1 to /main/welcome/2the controller reloads which I don't want it to.
In ui-router 1.0.0 you can use dynamic parameters:
Dynamic parameters (the replacement for reloadOnSearch) can be declared in a params block in a state definition like so: params; { fooParam: { dynamic: true } }. When a dynamic parameter changes, it does not cause the state to be reloaded. A controller/component callback uiOnParamsChanged may be used to be notified of parameter changes.
For example:
.state('main.welcome', {
url: '/welcome/:id',
params: {
id: {
dynamic: true
}
},
templateUrl: 'templates/welcome.html',
controller: 'greetingCtrl'
})
Demo: http://run.plnkr.co/uGARJoK2zxGVa2VL/#/main/welcome/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With