重定向页面时显示 Toastr 消息
Show Toastr message when redirecting page
我有一个在提交时调用以下函数的表单。
function addToCart(form) {
if (form.$valid) {
shopFactory.addToCart(vm.model.ProductDetail).then(function () {
toastr.success("Added to cart");
$window.location = "shop/myCart";
});
}
}
函数重定向到页面 myCart,并显示 Toastr 消息。
我的问题是当消息出现在用户被引导离开的当前页面上时,toastr 消息立即消失。
有没有办法让消息通过重定向来维持,或者只是出现在下一页?
在shop/myCart页面控制器中,在里面写代码,$stateChangeSucces
(如果使用ui.router)或$routeChangeSuccess
。还要检查之前的路线以确保toastr仅针对这种情况显示消息。
示例:
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
console.log("foo");
});
});
我有一个在提交时调用以下函数的表单。
function addToCart(form) {
if (form.$valid) {
shopFactory.addToCart(vm.model.ProductDetail).then(function () {
toastr.success("Added to cart");
$window.location = "shop/myCart";
});
}
}
函数重定向到页面 myCart,并显示 Toastr 消息。
我的问题是当消息出现在用户被引导离开的当前页面上时,toastr 消息立即消失。
有没有办法让消息通过重定向来维持,或者只是出现在下一页?
在shop/myCart页面控制器中,在里面写代码,$stateChangeSucces
(如果使用ui.router)或$routeChangeSuccess
。还要检查之前的路线以确保toastr仅针对这种情况显示消息。
示例:
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
console.log("foo");
});
});