angularjs - 从一个页面导航到另一个页面时如何显示消息
问题描述
在成功消息上,我想从上传的页面导航到客户页面并将我的警报突出显示为 success ,但我的警报没有打开。需要解决方案
上传.js
if (status == 200){
$state.go('customer', {"id": $scope.customer});
$rootScope.$emit('custSucess');
}
客户.js
$rootScope.$on('custSucess',function(event){
$scope.message = {
content: [{
title: '',
msg:'hi'
}],
type: 'success'
};
});
解决方案
所以我最终做的是创建一个服务来处理我的警报。这是服务代码:
app.factory('AlertService', function () {
var success = {},
error = {},
alert = false;
return {
getSuccess: function () {
return success;
},
setSuccess: function (value) {
success = value;
alert = true;
},
getError: function () {
return error;
},
setError: function (value) {
error = value;
alert = true;
},
reset: function () {
success = {};
error = {};
alert = false;
},
hasAlert: function () {
return alert;
}
}
});
//而且我只是在需要时设置它:
AlertService.setSuccess({ show: true, msg: name + ' has been updated successfully.' });
//并在显示它的页面上检查它:
if (AlertService.hasAlert()) {
$scope.success = AlertService.getSuccess();
AlertService.reset();
}`enter code here`
推荐阅读
- go - 自定义控制器在缓存同步之前对 addfunc 事件处理程序做出反应?这种行为正确吗?
- java - readInt 和 readLine 在 Java 中制作基本的加法机
- json - 使用 curl 使用 bashscript POST json
- mysql - MySQL如何将两个表(不同的字段)与两个语句组合起来
- c# - 使用单个源数据同时运行多个任务
- mysql - Mysql - 字符串A,B和B,A应该相同
- php - 如何更新 WooCommerce 订单商品数量
- javascript - 列出 Electron 中 ipcRenderer 的所有频道监听器
- python - 只有经过身份验证的用户才能访问媒体文件
- html - 在没有全屏浏览器的情况下在图像上显示全高(使用封面)