Reputation: 697
I wanted to send success message from one controller to another controller and trigger my error function to display my success message.But Success message is not displaying due to redirection.It works in same page scenario,but not when I wanted to redirect.Need assistance. from a.js tp b.js I am trying to do this scenario
a.js
if(status == 0){
$state.go('b');
$rootScope.$emit('aSaySuccess');
}
b.htlml
<px-alert type="message.type" messages="message.content"
red-warning="flag" modal="message.modal" modal="message.title"></px-alert>
b.Js
function openTheError() {
$scope.flag = true;
$scope.message = {
content: [{
title: '',
msg: 'Succcess'
}],
type: 'success'
};
};
$rootScope.$on('aSaySuccess',function(){
openTheError();
});
Upvotes: 0
Views: 91
Reputation: 9476
you can pass parameter $state.go("b", { isSuccess: true });
as Sameer commented. You can make param not to appear in url.
State go is async - but it return promise which is resolved when transition happens.
$state.go('b').then(function() { $timeout(function() { $rootScope.$emit('aSaySuccess') }, 0); // Not sure but probably you need another timeout here });
Upvotes: 1