要在重定向页面中显示的成功警报不起作用

Success alert to be displayed in redirected page not working

我想将成功消息从一个控制器发送到另一个控制器并触发我的错误函数以显示我的成功 message.But 由于 redirection.It 在同一页面场景中工作,因此未显示成功消息,但是不是当我想 redirect.Need 帮助。 来自 a.js tp b.js 我正在尝试做这个场景

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();
        });
  1. 您可以像 Sameer 评论的那样传递参数 $state.go("b", { isSuccess: true });。你可以让param不出现在url.

  2. 状态 go 是异步的 - 但它 return 承诺在转换发生时解决。

$state.go('b').then(function() {
   $timeout(function() { $rootScope.$emit('aSaySuccess') }, 0); // Not sure but probably you need another timeout here
 });