打开 Modal 并更改 URL 而不更改 AngularJS 中的视图 [英] Open Modal and change URL without change the view in AngularJS
本文介绍了打开 Modal 并更改 URL 而不更改 AngularJS 中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 angularjs 打开一个模态.
I'm trying to open a modal with angularjs.
我的任务列表路径是:
/client/:id/task/list
它工作正常.现在,我正在尝试以模式显示任务信息,位于列表上方.
Its working fine. Now, i'm trying to show the task info in a modal, above the list.
我的路线是:
/client/:id/task/:id
如何打开列表视图上方的模式,更改 URL,但不更改视图?
How can i open the modal above the list view, change the URL, but don't change the view?
我看到了很多关于这个的话题,但都没有解决方案.
I saw a lot of topics about this, but with none solution.
谢谢.
推荐答案
您可以指定要显示为模态的状态,并在处理时返回到您想要的状态.例如;
You can specify states you want to show as modal and when handled, return to state you want to. For example;
app.config(function ($stateProvider) {
$stateProvider.state('tasks', {
url: '/tasks',
templateUrl: 'tasks.html',
controller: 'TasksCtrl'
}).state("tasks.show", {
url: "/tasks/:id",
onEnter: function($stateParams, $state, $modal) {
$modal.open({
templateUrl: "show.html",
resolve: {},
controller: function($scope, $state) {
$scope.ok = function () {
$scope.$close();
};
$scope.dismiss = function () {
$scope.$dismiss();
};
}
}).result.then(function (result) {
// $scope.$close
}, function (result) {
// $scope.$dismiss
}).finally(function () {
// finally
return $state.transitionTo("tasks");
});
}
});
});
<小时>相关 plunker 在这里http://plnkr.co/edit/fCyrlH
Related plunker here http://plnkr.co/edit/fCyrlH
这篇关于打开 Modal 并更改 URL 而不更改 AngularJS 中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文