0

I have two controller Controller A and controller B . controller A has an object $scope.operation={}; which is a json containing details.

In controller B I want to compare the detail of this json object and then run a function in COntroller B .How to achieve this..Thanks

2
  • you can use $rootScope or Factory to communicate between controller Commented Oct 13, 2015 at 6:36
  • Is B's view nested in A's view? Where does the data come from? Commented Oct 13, 2015 at 6:36

1 Answer 1

3

Use a factory/service to store the operations array, whenever the value changes in the ControllerA controller update the values in service.

myApp.factory('myService', [function() {
        var operations = {};
        return {
            getOperations: function() {
                return operations
            },

            setOperations: function(op) {
                operations = op;
            },
        }
    }])
    .controller('ControllerA', [function($scope, myService) {
        $scope.operations = {};
        $scope.$watch(function() {
            return $scope.operations;
        }, function() {
            myService.setOperations($scope.operations);
        });
    }])
    .controller('ControllerB', [function($scope, myService) {
        $scope.operations = myService.getOperations();
    }]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.