将模态数据传递给angularjs中的另一页

时间:2016-05-25 11:10:34

标签: angularjs angularjs-scope

我需要将数据从模态传递到另一个页面,我的模态承诺函数就像这样,

modalInstance.result.then(function (product) {
        $scope.selectedProduct = product;
        $location.path('cart');            
    });

请注意,我需要将产品数据发送到新页面“购物车”。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

app.serivce('commonService', 
    function(){
        this.sharedData = 'Shared Data';

        this.getSharedData = function(){
            return this.sharedData;
        };

        this.updateSharedData = function(updatedData){
            this.sharedData = updatedData;
        };
    }
);

app.controller('ctr1', ['$scope', 'commonService',
    function($scope, commonService){
        // Call this function from modal to update sharedData
        $scope.updateData = function(newData){
            commonService.updateSharedData(newData);
        };
    }
]);


app.controller('ctr2', ['$scope', 'commonService',
    function($scope, commonService){
        // Call this function to retrieve sharedData
        $scope.loadSharedData = function(){
            commonService.getSharedData();
        };
    }
]);