我刚刚开始使用 Angular js。对此我有疑问。我想在重定向后设置闪现消息。
就我而言,我有一个表单并通过 http 请求保存数据。在成功函数中我放置了 window.location()。这是另一页。我想在该页面中设置一条即时消息。
js
$scope.Save_Details = function (id)
{
$http.post(base_url+"sur/sur/save_data/"+id,{data:$scope.Surdata}).
success(function(response) {
// $scope.successTextAlert = "Saved";
// $scope.showSuccessAlert = true;
window.location = "#/surpage/nextpage?show_message= true";
});
}
新更新
var messageFlag = $location.search().show_message;
if(messageFlag && messageFlag === 'true'){
alert(messageFlag);
$scope.successTextAlert = "Saved";
$scope.showSuccessAlertMsg = true;
}
查看
<div class="alert alert-success" ng-show="showSuccessAlert">
<button type="button" class="close" data-ng-click="switchBool('showSuccessAlert')">×</button> <strong> {{successTextAlert}}</strong>
</div>
有人帮助我吗?
最佳答案
将此代码放入 HTML -
<!-- message text -->
<div class=" panel-{{alerts.class}}" ng-show="alerts.messages" >
<div ng-repeat="alert in alerts.messages track by $index" class="panel-body alert-{{alerts.class}}" >{{alert}}</div>
</div>
将此代码放入 Angular 模型中 -
$rootScope.alert = function(type,msg){
$rootScope.message.push(msg);
$rootScope.alerts = {
class: type,
messages:$rootScope.message
}
}
成功消息 -
$rootScope.alert('success',"Success !!!");
对于错误消息 -
$rootScope.alert('danger',"Error.");
关于javascript - 在AngularJS中重定向后设置Flash消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073180/