Amit Patil
Amit Patil

Reputation: 3067

Clear Angularjs state.go parameters

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 ?

Upvotes: 0

Views: 1972

Answers (1)

Gaurav
Gaurav

Reputation: 1233

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

Upvotes: 4

Related Questions