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?

1 Answer 1

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.

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.