0

I am pretty new to angularjs and still getting used to the concepts.

This is the premise of my problem- I have 2 peer controllers (no parent child relationship), controller1 does say steps 1 to 10, controller 2 does something else until it finds something which is the step 7 of controller 1. So after that controller 2 needs to do the same last steps. Is there a way I can call a function in controller 1 from controller 2 so that there is no code replication. Do I need to create a service for this or is there a way to just call a function in another controller from one in angularjs

I have seen these 2 links and am wondering if there is an easier way to just call a function in another controller from one , may be using $rootscope.

Passing data from one controller to other Angular

AngularJS: How can I pass variables between controllers?

Community
  • 1
  • 1
curious123
  • 53
  • 11

1 Answers1

2

As the author of angular said himself in Angular Best Practices video, if your trying to figure out how to call one controller for another controller, you probably should be using a service.

MichaelLo
  • 1,289
  • 1
  • 14
  • 26