问题
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