Clear Angularjs state.go parameters

蹲街弑〆低调 提交于 2021-01-19 11:32:27

问题


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 ?


回答1:


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} );



来源:https://stackoverflow.com/questions/42445910/clear-angularjs-state-go-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!