-
Notifications
You must be signed in to change notification settings - Fork 52
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
flash messages on multiple pages is not working #28
Comments
You're dealing with different scopes. In it's current form, angular-flash cannot flash.to() a DOM element that doesn't exist (yet). If you attempt to flash.to() an element on the page of your current scope, you'll see that it is working. I was having the same issue, so I simply created a catch-all alert (not assigning an id to the alert element) on the second page. |
@mark : Thanks for you response. Even catch all alert is not working on second page. If I remove {{flash.message}} div element in the first page, then flash message works in second page. Its like I can either one of the flash message, not both. |
Hi @SrividyaKasu, Thanks for posting this issue. Can you provide more detailed HTML and JS snippets of page 1 and page 2 and controller 1 and controller 2? Thanks, |
Hi Luke and Mark, I work for the same company as Srividya. I attempted to fix this problem and have a patch that seems to work and is compatible with the existing functionality. (As much as I can see.) I've created a pull request please revise and perhaps approve if you find it useful. Best regards |
Hi Marton, Thanks for the PR, but before we go there I'd like to get a better understanding of this issue. Please include some more detailed template and controller examples so that I can dig deeper. Thanks again, |
Hi Luke, Thanks for your reply. I've compiled a package with the example files. They are commented and I've deleted most of the content to make it simpler and more transparent. If I've deleted too much or you need more information please let me know. Regards |
Hi Luke, I do not mean to rush you, I just wondered if you perhaps had a chance to look at the ZIP file I have sent, or you need more information from us? Regards |
Hi Marton, Thanks for following up. Admittedly, I've been preoccupied learning how to be a first time father. The online docs for these newborn platforms isn't so great ;-). Fingers crossed, I'm hoping to get caught up this weekend. Thanks again for contributing. Luke
|
Haha, that is fantastic, congratulations! Best regards |
Hi Luke, Is there any chance you will be able to review the pull request anytime soon? Bests |
Any updates on this? I have the same issue. The flash on the first page receives the message and directly cleans in on the destroy event. The code looks a bit like this function Controller($scope, $route, flash) {
$scope.submit = function() {
// Model update omitted for brevity.
flash.success = 'Model updated';
// Easier to reload all models and the changed
// dependencies than to keep track of state.
$route.reload();
};
} |
Hi Mark, If you want you can clone my branch then use it something like this. function Controller($scope, $route, flash) { It will carry your message on to the next page or until reload. Bests |
Hi Folks, Sorry for the radio silence. I've been pondering how to best support this behavior. Initially, I envisioned But it seems that you guys would like to use it more like the HTTP session flash pattern popularized by rails flash. With Rails, the flash message is persisted within the HTTP session and then displayed and removed with the next HTTP request. So Rails flash involves state and leverages the the HTTP request cycle to determine when to show and remove the persisted flash. In contrast, angularjs apps (single page HTML5 apps in general) don't have a common request cycle and session state to leverage. For routing, some apps use Admittedly, the name In the meantime, I can bake-in something like Here are some examples: // Publish this `success` alert after the next `$routeChangeSuccess` event.
flash.on('$routeChangeSuccess').success = 'Hello from the previous page';
// Roll your own event callback: Publish this `info` alert after this scope is destroyed
function onDestroy(notify, type, message) {
$scope.$on('$destroy', function () {
$timeout(notify);
});
}
flash.on(onDestroy).info = 'bye bye from about page'; Thoughts? Thanks again for your patience and continued feedback, |
Hey @wmluke I also intended to use it for multiple pages. Did you end up implementing this, or is there any workaround to do this right now? |
My solution is to have a separate EDIT: More details. <body>
<div ng-controller="HeaderCtrl">
<nav><!-- etc. --></nav>
<div id="messages">
<div flash-alert active-class="in alert" class="fade">
<span class="close" ng-click="hide()">
×
</span>
<strong class="alert-heading">FYI.</strong>
<span class="alert-message">{{flash.message}}</span>
</div>
</div>
</div>
<div id="main" ui-view></div><!-- or ng-view if you prefer -->
</body> app.controller('SomeCtrl', ['flash', function (flash) {
flash.error = 'Check yourself before you wreck yourself.';
}]); Actually, there's no reason to have the separate control: as long as the |
Just to chime in, I ended up using @StevenClontz's solution and it worked well. This feels more like the "correct" way to do it, as opposed to some blob of data persisting throughout navigation events. |
Instead of always having to use angular-flash in a high-level scope (above the view/ui-view), why not retain the messages in the angular-flash service, like in angular-flare? It wouldn't force a particular design pattern and would let one access the flash messages without the worry of them getting nuked with the directive. |
When I have flash messages in consecutive views, flash message on second page is not shown. Please check the below code. flash to strategy also is not working(
flash.to('alert-1').info = 'Only for alert 1';) It seems like page 1 swallowing flash message destined to page 2.
Page 1
Page 1 controller
flash.success = 'Deletion was successful.';
Page 2
The text was updated successfully, but these errors were encountered: