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

问题描述 投票:0回答:1

我想将成功消息从一个控制器发送到另一个控制器并触发我的错误功能以显示我的成功消息。但是由于重定向而没有显示成功消息。它在同一页面场景中工作,但在我想重定向时不行。需要帮助。来自a.js tp b.js我正在尝试这种情况

a.js

if(status == 0){
 $state.go('b');
 $rootScope.$emit('aSaySuccess');
}

b.html

<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();
        });
angularjs angular-ui-router angular-directive
1个回答
1
投票
  1. 你可以传递参数$state.go("b", { isSuccess: true });作为Sameer评论。您可以使param不显示在url中。
  2. 状态go是异步的 - 但是它会返回在转换发生时解决的promise。
$state.go('b').then(function() {
   $timeout(function() { $rootScope.$emit('aSaySuccess') }, 0); // Not sure but probably you need another timeout here
 });
© www.soinside.com 2019 - 2024. All rights reserved.