将数据从modal传递到angularjs中的另一个页面

时间:2016-05-24 23:54:39

标签: angularjs angularjs-scope

我需要将数据从模态传递到另一个页面。你能帮我完成这个任务吗?

 $scope.productdetails = function (size,selectedproduct)
     {       
    var modalInstance = $uibModal.open({           
    templateUrl: 'ProductDetails.html',            
    controller: function ($scope, $uibModalInstance, product) {
        $scope.product = product;

        $scope.buynow = function (path) {
            $uibModalInstance.close($scope.product);
            $location.path(path); // Need to pass $scope.product to the new page
        };

        $scope.cancel = function () {
            $uibModalInstance.dismiss('cancel');
        };
    },
    size: size,
    resolve: {
        product: function () {
            return selectedproduct;
        }
    }
});        

1 个答案:

答案 0 :(得分:1)

请务必阅读$uibModalhttps://github.com/angular-ui/bootstrap/tree/master/src/modal/docs

上的文档

open()方法将返回一个包含一些有用内容的对象。目前你没有对这个对象做任何事情,但这就是魔术所在。

要将数据传递给打开模态的控制器,请使用modalInstance.result这样的承诺:

modalInstance.result.then(function(data) { /*... do something with the data*/ });

设置完成后,您可以使用此模式库放置在作用域上的$close()函数来解析result承诺。

var data = {info: 'information to be returned to the parent controller'};
$scope.$close(data);