2

I have two controllers. There are functions that are identical and others that are differ.

For example:

Controller 1:

app.controller('ControllerOne', ['$scope','HelperService',
    function ($scope, HelperService) {
        $scope.helperService = HelperService; //get an instance of the HelperService

        $scope.select = function () {
            $scope.helperService.doA();
            $scope.helperService.doB();
            $scope.helperService.doC();
        };

        $scope.filter = function () {
            $scope.helperService.doB();
            $scope.helperService.doC();
            $scope.helperService.doE();
            $scope.helperService.doF();
        };
    }
]);

The second controller:

app.controller('ControllerOne', ['$scope','HelperService',
    function ($scope, HelperService) {
        $scope.helperService = HelperService; //get an instance of the HelperService

        $scope.select = function () {
            $scope.helperService.doA();
            $scope.helperService.doB();
            $scope.helperService.doC();
            $scope.helperService.doD();
        };

        $scope.filter = function () {
            $scope.helperService.doB();
            $scope.helperService.doC();
            $scope.helperService.doD();
            $scope.helperService.doF();
        };
    }
]);

I have partials html to use the same click event but it depends on the controller:

<div ng-click="select()"></div> 

How can I avoid from duplicated code on both controllers?

1

0

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.