Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs: How to reload or refresh ui-view using ui-router

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.

like image 539
Anil Kumar Pandey Avatar asked Aug 19 '13 06:08

Anil Kumar Pandey


3 Answers

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.

like image 184
blockloop Avatar answered Oct 29 '22 10:10

blockloop


Try adding target="_self" to the a. You can also use $window.location. Also $route.reload() should do the trick.

like image 22
fusio Avatar answered Oct 29 '22 11:10

fusio


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});
like image 25
Jyoti Adhikari Avatar answered Oct 29 '22 11:10

Jyoti Adhikari