如何在删除AngularJS中的项目后重新加载状态?
问题描述:
在我的项目中,点击删除按钮,调用一个函数,在里面用delete方法调用api。从projectlist成功删除项目后,我正在重新加载状态。这里的问题是,我正在将URL传递给项目ID。因此,在删除项目后,项目ID仍然存在于URL中,这是因为为什么状态重新加载已经删除了项目ID,它已经在URL中被重新加载,其中没有值。如何在删除AngularJS中的项目后重新加载状态?
下面给出了更好地理解代码的代码。
survey.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()
这是该控制器内部
surveyController.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});
。这个$ state.go()与id = 0是默认的我想重新加载。
答
你试过这个吗$state.go('survey.surveyList',{id: 0}, {reload : true});
?
参考: https://github.com/angular-ui/ui-router/wiki/quick-reference#toparams
+0
谢谢它为我工作.. – Kishan
你只是想从列表中删除已删除的记录,对不对? –
'state'对象是如何初始化的?对我来说,它应该是:'$ state.reload();'。 – Zakaria