Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
May be this topic hepl you [stackoverflow.com/questions/11267284/… [1]: stackoverflow.com/questions/11267284/… –  iKBAHT Sep 27 '13 at 10:25

2 Answers 2

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

share|improve this answer
    
target="_self" not working... and where to put $window.location or $route.reload(), because its not working inside HomeController –  user2518430 Aug 19 '13 at 6:51
    
you need to import the $window or the $route respectively into the controller in order to use them –  fusio Aug 19 '13 at 7:14
    
Thanks for suggestions @fusio but its not working. May be its because I am using ui-router and it has state provider, I have also tried $state.transitionTo("home") but its also not working any more –  user2518430 Aug 19 '13 at 9:59
    
Oh, I see. Did you try $state.go()? (it should use transitionTo internally, so I am not sure it will help..) –  fusio Aug 19 '13 at 10:05
    
Yes, but it throws an error in console TypeError: Object #<Object> has no method 'go' its because $state.go() is available in Latest alpha 0.0.2 version and its not a stable version thats why I am using previous version 0.0.1. –  user2518430 Aug 19 '13 at 10:22

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.