我想将成功消息从一个控制器发送到另一个控制器并触发我的错误功能以显示我的成功消息。但是由于重定向而没有显示成功消息。它在同一页面场景中工作,但在我想重定向时不行。需要帮助。来自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();
});
$state.go("b", { isSuccess: true });
作为Sameer评论。您可以使param不显示在url中。$state.go('b').then(function() { $timeout(function() { $rootScope.$emit('aSaySuccess') }, 0); // Not sure but probably you need another timeout here });