清除Angularjs state.go参数 [英] Clear Angularjs state.go parameters

查看:186
本文介绍了清除Angularjs state.go参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angularjs应用程序.就像CRUD应用一样.下面是应用程序结构

I am working on angularjs app. Its like CRUD app. Below is the app structure

Home (List)        => "/#!/"
--- Details page   => "/#!/home/details/-KcXruMX3ia6rokeZjCJ"
----- Edit page    => "#!/home/edit/-KcXruMX3ia6rokeZjCJ"

在编辑页面后,我将用户重定向到详细信息页面,并显示以下成功消息.

After edit page I redirect user to details page with success message as below.

$scope.msg = {type : "success","msg" : "User Updated"};
$state.go('home.details', { id : $scope.id, msg : $scope.msg });

直到这一步都可以正常工作,问题是当我单击其他用户/项目并进入详细信息页面时,我仍然看到该消息.

Till this step it works fine, Problem is when I click on other user/item and come to details page I still see that message.

下面是我的详细信息控制器

Below is my details controller

myApp.controller("detailsCtrl",[
        "$scope",
        "$stateParams",
    function(
        $scope, 
        $stateParams, 
    ){
    // msg variables receives its values from previous actions 
    $scope.msg = $stateParams.msg;

}]);

如何使用一次清除该消息?

How can I clear that message by using it once ?

推荐答案

如果您正在使用 ui-sref ,那么您还可以提供状态参数,例如 ui-sref ="details({msg:''})"或如果要清除状态参数,则当您转换到当前状态时,可以提及 $ state.go('.',{msg:undefined});

If you are using ui-sref then threre you can also provide the state params like ui-sref="details({msg: ''})" or if you want to clear the state params, when you are transitioning into current state you can mention $state.go('.', {msg: undefined} );

这篇关于清除Angularjs state.go参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆