Open Modal and change URL without change the view in AngularJS

Deadly 提交于 2020-01-13 05:48:50

问题


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.

My route for this is:

/client/:id/task/:id

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.

Thanks.


回答1:


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


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



来源:https://stackoverflow.com/questions/26470555/open-modal-and-change-url-without-change-the-view-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!