0

My controllers have one function that has to be shared between more of them (now I just copied it):

example:

   $scope.selectedPartner = { "Name": "", "Id": null };

   $scope.selectPartner = function ($item) { $scope.selectedPartner = $item; };

    $scope.getPartners = function (name) {
        $scope.selectedPartner = { "Name": "", "Id": null };

        return autoComplete.getPartners(name).then(function (response) {
            return response.data.Partners;
        });
    };

And a lot of other functions. How can I make something like partnersFunctions() to include these functions to all controllers without copying?

2
  • Why not make a service and then just inject that service into your different controllers? Commented May 5, 2014 at 19:30
  • Well, I need help about that. I just know how to make a service that returns $http, nothing more. Any resources? Commented May 5, 2014 at 19:31

1 Answer 1

4

This is where you may find using a service handy. Check out the documentation at: https://code.angularjs.org/1.2.5/docs/guide/dev_guide.services.creating_services

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.