gpt4 book ai didi

javascript - 在AngularJS中重定向后设置Flash消息

转载 作者:行者123 更新时间:2023-11-27 22:36:15 25 4
gpt4 key购买 nike

我刚刚开始使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com