0

I have two controllers and I'm using a factory to declare objects. In the main controller I call the other like this:

var a = $controller('otherController', {$scope: $scope});

In the second controller, I have a function and I want to return an array to make something in the main

$scope.function = function(items){

        //some data things

        return auxItems;
    };

The question is, in the main I call the function but I need the return to work. How can I "wait" the return in the main controller?

David Luque
  • 1,078
  • 5
  • 18
  • 30
  • Possible duplicate of [What's the correct way to communicate between controllers in AngularJS?](http://stackoverflow.com/questions/11252780/whats-the-correct-way-to-communicate-between-controllers-in-angularjs) – Raduan Santos Oct 13 '15 at 11:24
  • If you need to communicate between controllers, it means you should rethink your design (in 99% of cases). Keep in mind that business logic should be put into services, not in controllers – LionC Oct 13 '15 at 11:29

2 Answers2

0

This is not the way to communicate between controllers. Use $scope.$on and $rootScope.$broadcast instead.

A much more detailed explanation can be found here:
What's the correct way to communicate between controllers in AngularJS?

Community
  • 1
  • 1
Artless
  • 4,522
  • 1
  • 25
  • 40
0

Actually you can comunicate between classes using services. You can check this link link

But the problem is you should not need to comunicate two sibling classes. Rethink your design

Community
  • 1
  • 1
Utku Apaydin
  • 162
  • 1
  • 4