I am using angular ui-router. It has state in each routing, but I am not able to reload the state. Here are my code
app.config(function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise("/home");
$stateProvider
.state('home', {
url: "/home",
controller: 'HomeController',
views: {
"viewHome": {
templateUrl: "home.html"
},
})
}
in HTML
<a href="#/home">Home</a>
When I clicked on Home link then it redirected to home url but when I was trying to click again the home link then its not refresh the same state, It must be refresh the home state and again call the HomeController. Please give me some solution for this.
Using angular-ui-router I'm successfully reloading a state with:
$state.go($state.current.name, {}, {reload: true})
This reloads the state and re-inits the controller.
Try adding target="_self"
to the a
. You can also use $window.location
. Also $route.reload()
should do the trick.
You can give which state you want to call it's will reload your page and controller. This code is working for me:
$state.go($state.current.name, {}, {reload: true})
or
$state.go('state.name',{},{reload:true});
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