简体   繁体   English

在 AngularJS 中删除项目后如何重新加载状态?

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

In my project on click of the delete button am calling one function and inside that am calling the api with delete method.在我的项目中,单击删除按钮正在调用一个函数,并在其中使用 delete 方法调用 api。 After successfully deleting the Project from projectlist i am reloading the state.从项目列表中成功删除项目后,我正在重新加载状态。 Here problem is, i am passing the project id in the URL.这里的问题是,我在 URL 中传递项目 ID。 So after deleting the item the project id is still there in the url, because of why on state reload already deleted project id which is already there in the url is reloaded with no value inside it.因此,在删除项目后,项目 id 仍然存在于 url 中,因为在状态重新加载已删除的项目 id 中,已经存在于 url 中的项目 id 被重新加载,其中没有任何值。

Below am giving the codes for better understanding of the code.下面给出代码以便更好地理解代码。

survey.html调查.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 (using UI routing) 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 this is where am showing the delete confirmation popup 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>

On click on this button am calling projectDelete() which is inside this controller单击此按钮会调用位于此控制器内的projectDelete()

surveyController.js调查控制器.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");
      });
   };

I tried with state.reload() and $state.go('survey.surveyList',{id: 0});我试过state.reload()$state.go('survey.surveyList',{id: 0}); . . This $state.go() with id=0 is default one which i want to reload.这个带有 id=0 的 $state.go() 是我想要重新加载的默认值。

did you try this $state.go('survey.surveyList',{id: 0}, {reload : true});你试过这个$state.go('survey.surveyList',{id: 0}, {reload : true}); ? ?

reference : https://github.com/angular-ui/ui-router/wiki/quick-reference#toparams参考: 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