打开Modal并更改URL,而无需更改AngularJS中的视图 [英] Open Modal and change URL without change the view in AngularJS

查看:91
本文介绍了打开Modal并更改URL,而无需更改AngularJS中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用angularjs打开一个模式.

I'm trying to open a modal with angularjs.

我到任务列表的路线是:

My route to task list is:

/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");
      });
    }
  });
});


相关此处的插件 http://plnkr.co/edit/fCyrlH


Related plunker here http://plnkr.co/edit/fCyrlH

这篇关于打开Modal并更改URL,而无需更改AngularJS中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆