Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcing router refresh #23

Open
vredchenko opened this issue Nov 6, 2013 · 7 comments
Open

Forcing router refresh #23

vredchenko opened this issue Nov 6, 2013 · 7 comments

Comments

@vredchenko
Copy link

Already on SO: http://stackoverflow.com/questions/19812911/is-it-possible-to-refresh-route-segment-provider-in-angularjs

Basically, I'm using:

resolve: ['isUserLoggedIn'],
resolveFailed: {
templateUrl: 'assets/templates/login.html',
controller: LoginCtrl
}

to redirect to login page if user is not yet logged in.
The login controller redirects back to /#/index if user logged in successfully, but it seems that templateUrl and controller have already been decided and they don't get refreshed, isUserLoggedIn does not get called for the second time. Is this intended behaviour? Is there a way to forcefully refresh routing after initial setup?

@philipdouglas
Copy link

Did you find a solution for this? I have run into the same problem.

@vredchenko
Copy link
Author

This seems to do the trick:

.segment('index', {
            templateUrl: 'assets/templates/index.html',
            controller: IndexCtrl,
            dependencies: ['index'],
            resolve: {
                data: function(Article, $q, $location) {
                    var deferred = $q.defer();
                    Article.getAll().get({},
                        function(successData) {
                            deferred.resolve(successData);
                        }, function(errorData) {
                            deferred.reject();
                        });
                    return deferred.promise;
                }
            },
            untilResolved: {
                templateUrl: 'assets/templates/loading.html'
            },
            resolveFailed: {
                // ToDo: Error template and controller should be here.
                templateUrl: 'assets/templates/login.html',
                controller: LoginCtrl
            }})

@philipdouglas
Copy link

What does your LoginCtrl do on a successful login to reload the index segment?

@vredchenko
Copy link
Author

$location.path('/index');

@vredchenko
Copy link
Author

We've still got a bug with this approach - we'll post a solution here (and on SO) once we've fixed it.

@vredchenko
Copy link
Author

FYI we ended up with a hack, forcefully refreshing the entire page in order to refresh the router. Had a deadline and no time to play around and get to the bottom of things :(

@artch
Copy link
Owner

artch commented May 13, 2014

Did you have a look to watcher property?

.segment('index', {
    ...
    watcher: function(injectables) {
        ...
        return result; // when result is changed, the segments gets reloaded
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants