簡體   English   中英

在 AngularJS 中刪除項目后如何重新加載狀態?

[英]How to reload the state after deleting an item in AngularJS?

在我的項目中,單擊刪除按鈕正在調用一個函數,並在其中使用 delete 方法調用 api。 從項目列表中成功刪除項目后,我正在重新加載狀態。 這里的問題是,我在 URL 中傳遞項目 ID。 因此,在刪除項目后,項目 id 仍然存在於 url 中,因為在狀態重新加載已刪除的項目 id 中,已經存在於 url 中的項目 id 被重新加載,其中沒有任何值。

下面給出代碼以便更好地理解代碼。

調查.html

   <ul class="sidebar-nav">
            <li class="sidebar-brand" >
                <a>
                    Projects
                </a>
            </li>
            <li ng-repeat="obj in allProjects track by  $id(obj)">
                <a ui-sref="survey.surveyList({id: obj.ProjectID})" ng-click="getProjSurveys(obj.ProjectID)" ui-sref-active="activeProject" ng-init="getReloadProjSurveys()">{{obj.ProjectName}}<span class="projectsetting" ng-click="sendProjectID(obj.ProjectID)"><img src="./images/settings.png"/></span></a>
            </li>
         </ul>
       <div class="surveyContainer" ui-view></div>

index.js(使用 UI 路由)

   .state('survey', {
        url: '/survey',
        views:{
            header:{
                templateUrl: 'common/headerTool.html',
                controller: 'headerController'
            },
            pageContent:{
                templateUrl: 'survey/survey.html',
                  controller: 'surveyController'
            },
            footer:{
                templateUrl: 'common/innerFooter.html',
                controller: 'footerController'
            }
        }
    }).state('survey.surveyList', {
        url: '/:id',
        templateUrl: 'survey/surveyList.html',
        controller: ''
    });

popup.html這是顯示刪除確認彈出窗口的地方

  <div class="modal fade" id="deleteProject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
   <div class="modal-dialog" role="document">
    <div class="modal-content">
     <div class="modal-body">
        <p class="text-center">Are you sure you want to delete this project</p>
     </div>
    <div class="modal-footer">
     <div class="col-md-6 text-right"><span type="button" class="cancel" data-dismiss="modal">Cancel</span></div>
     <div class="col-md-offset-1 col-md-5 text-left"><span type="button" class="success" value="Delete" ng-click="projectDelete()" >Delete</span></div>
    </div> 
  </div>

單擊此按鈕會調用位於此控制器內的projectDelete()

調查控制器.js

  $scope.sendProjectID = function(ProjectID){
     $scope.ProjectID = ProjectID;
   };
  $scope.projectDelete = function($event){
      $("#deleteProject").hide();
       UserService.DeleteProject($scope.ProjectID).then(
       function( data ) {
          console.log(data);
          state.reload();
         //$state.go('survey.surveyList',{id: 0});
         $("#deleteProject").modal("hide");
      });
   };

我試過state.reload()$state.go('survey.surveyList',{id: 0}); . 這個帶有 id=0 的 $state.go() 是我想要重新加載的默認值。

你試過這個$state.go('survey.surveyList',{id: 0}, {reload : true}); ?

參考: https : //github.com/angular-ui/ui-router/wiki/quick-reference#toparams

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM