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

$locationChangeSuccess called after controllers are initialized #38

@andreasellervee

Description

@andreasellervee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions