I have been trying and searching for articles on this and what i found out is adding state dynamically on runtime only. The closest to the solution i find is make use of deferIntercept
, $urlRouter.sync()
and $urlRouter.listen()
. However, it seems that $urlRouter
can only be used in runtime (which run before controller user action).
This plunker shows working dynamic added state into runtime but the challenge is to implement it in controller instead.
below is illustration to what i intend to achieve. I have been struggling on this issue for weeks. Hope someone could give me some hint on how to acheived the desire outcome.
// Predefined state in config
$stateProvider.state('default', {
url: '',
templateUrl: '',
})
// Predefined state in config
$stateProvider.state('home', {
url: '',
templateUrl: '',
})
// Additional Added state in controller when user click button
$scope.clickButton = function () {
$stateProvider.state('newpage', {
url: '',
templateUrl: ''
})
};