0

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 ?

5
  • when the detail page loading can you make $scope.msg = {} Commented Feb 24, 2017 at 18:35
  • Then it will not show success message. Commented Feb 24, 2017 at 18:36
  • How do you go to the details page? 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} ); Commented Feb 24, 2017 at 20:06
  • @Gaurav : Ahha thats it, thats what i wanted. ui-sref="details({msg: ''})". Can you please post it as answer so i can mark it as solved. Commented Feb 24, 2017 at 20:10
  • I've added that as an answer. Commented Feb 24, 2017 at 20:12

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.