Angular Js, call two functions with ng-click in different controllers

I have two buttons, both sit in different views and different controllers.

test1.cshtml -
<button ng-click="SaveToMyArea()" >Save to my area</button>

test2.cshtml -
<button ng-click="Save()">Save</button>

controller.js -
controller.controller("AppController", function ($scope, ExchangeService, $rootScope) {
      $scope.SaveToMyArea = function () {
        location.href = g_config.Urls.SaveToMyArea;

controller.controller("ActionController", function ($scope, $routeParams, $route, ActionService, ActionHelperService, $timeout, ExchangeService, $location, $rootScope, $translate) {
      $scope.Save = function () {
        var data = ActionHelperService.ConvertToSaveData($scope.Data);      

        ActionService.setAction($scope.actionId, $scope.type, data, $scope.Data, function () {
            $scope.Original = angular.copy($scope.Data);



Both buttons work fine individually. What I would like to do is to trigger both the 'Save' and 'SaveToMyArea' function when the SaveToMyArea button is clicked, how can I achieve this?
So it will Save, then SaveToMyArea.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
Controllers should not have dependencies between them.
If you have common logic, create a factory and move those functions there.
Like this you can simply reference the factory on both controllers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Al4ddin2Author Commented:
Hi thanks,

What I ended up doing was achieving this by creating some 'on' listeners and broadcasting a message between controllers.

Alexandre SimõesManager / Technology SpecialistCommented:
Although it works, events are more expensive and they don't isolate the code in a reusable way.
The second consequence of that approach is that you won't be able to test your common code, which you should (or at least write it in a way that it's testable).

In Angular, whenever you need to share functionality, you should create a Factory or Service.

Controllers (as in any MVC architecture) should serve the single purpose of gluing the business logic and with the UI.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.