如何使模式窗口打开动态内容并更改url


How to make modal window open dynamic content and change url?

我想让模式窗口像这个网站一样打开不同的路由http://architizer.com/projects/rauchkuchlhaus-auf-der-seewiese-am-schliersee-1/

流程为:

  1. 为模式窗口创建路由状态
  2. 将模式打开逻辑放入onEnter属性中(当路由更改为当前状态时将运行)
  3. 最后,所有项目(应该打开新的模式)都应该有引用来更改具有所需参数ui-sref="home({foo: 'fooVal1'})"的路由

你可以在ui路由器模式的常见问题中找到答案

$stateProvider.state("items.add", {
url: "/add",
onEnter: ['$stateParams', '$state', '$modal', '$resource', function($stateParams, $state, $modal, $resource) {
    $modal.open({
        templateUrl: "items/add",
        resolve: {
          item: function() { new Item(123).get(); }
        },
        controller: ['$scope', 'item', function($scope, item) {
          $scope.dismiss = function() {
            $scope.$dismiss();
          };
          $scope.save = function() {
            item.update().then(function() {
              $scope.$close(true);
            });
          };
        }]
    }).result.finally(function() {
        $state.go('^');
    });
}]
});