清除 Angularjs state.go 参数 [英] Clear Angularjs state.go parameters
问题描述
我正在开发 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屋!