Rubel
Rubel

Reputation: 71

Pass modal data to another page in angularjs

I need to pass data from modal to another page, My modal promise function like this,

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

Note that, Here I need to send product data to the new page 'cart'. How can I do this?

Upvotes: 0

Views: 46

Answers (1)

seekers01
seekers01

Reputation: 560

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();
        };
    }
]);

Upvotes: 1

Related Questions