当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - Save data and scroll of previous state when opening new state in modal window (Instagram/Pinterest routing)

问题描述:

I want to create routing like on the Instagram/Pinterest. In my case - open full article in the modal window. From FAQ

I find this code:

 $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.then(function(result) {

if (result) {

return $state.transitionTo("items");

}

});

}]

});

It works ok, but when I'm closing modal window, the scroll and data of the previous state are not saved. Whether there is an existing solution that retains scroll and data from the previous state after closing modal?

网友答案:

I've implemented "Sticky States" in ui-router-extras. Ui-router-extras is an addon module for ui-router. I have a modal example/demo which I believe does what you want to do. Visit the example here:

http://christopherthielen.github.io/ui-router-extras/example/stickymodal/index.html#/people/manager/0/emp/25

Then check out the main ui-router-extras page here: http://christopherthielen.github.io/ui-router-extras

分享给朋友:
您可能感兴趣的文章:
随机阅读: