0

In indexController.js of index.html, I want to call a method of loginController.js which does not belong to index.html. I already tried the following way: Firstly, I imported the controller in index.html by using

<script src="loginController.js"></script>

After that, I used $emit to call the method of loginController.js but I was failed. I suppose that loginController.js is not initialized in index.html, it does not belong to the module of index.html as well so it is not available for indexController.

I hope to be received some useful suggestion so I can resolve this problem.

1 Answer 1

1

You should use services instead in between controllers. Every controller has its own function scope, so unless they are nested, even then it's not a good practice, it won't work.

Create a loginService with the methods you need, then use it anywhere you want.

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.