Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

$locationChangeSuccess called after controllers are initialized #38

Open
andreasellervee opened this issue Jul 25, 2016 · 2 comments
Open

Comments

@andreasellervee
Copy link

Coming from $state.go(...) (https://github.com/angular-ui/ui-router), $locationChangeSuccess is called AFTER controller are initialized and views are loaded. This causes a small problem displaying messages.

Scenario:
I call $state.go('newState') and controller A gets initialized.
controller A has a method init() which will call messageCenterService.add('info', 'Message', options);
AFTER this, angular will now broadcast $locationChangeSuccess and the following happens:

// Update 'unseen' messages to be marked as 'shown'.
messageCenterService.markShown();
// Remove the messages that have been shown.
messageCenterService.removeShown();

(https://github.com/e0ipso/message-center/blob/master/message-center.js lines 125-132)

Because the newly created info-message is in an 'unseen' state, it will be marked as 'shown' and removed. Due to this, after everything is loaded, user can't see the message.

Workaround for this is to also listen to $locationChangeSuccess in controller A and recall the message.

$rootScope.$on('$locationChangeSuccess', function locationChanged(event, to) {
    showMessage();
});

But this needs a better solution, not a hack.

@jaimeguaman
Copy link

+1

@jaimeguaman
Copy link

jaimeguaman commented Nov 22, 2016

My workaround was changing listener from $locationChangeSuccess to $stateChangeSuccess` which is fired by ui-router

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

No branches or pull requests

2 participants