3

I am new to Angularjs and have a scenario where two pages using 2 modules on each page ie M1 and M2. Both modules having his own controllers C1 & C2. I want to pass value from C1 to C2. I tried with service but its not working. Can able to set value in first page but get value null on second page.

Can someone point me in the correct direction how to pass values between modules?

7
  • It is not quite clear from your question whether you want to pass values from one controller to the other on the same module or you want to pass value from one module to another Commented Sep 16, 2015 at 13:39
  • Need to pass value from controller C1 in module M1 to controller C2 in module M2. Modules are on different page e.g M1, C1 in login page and M2,C2 in home page so after click on login button need to pass value to home page. Commented Sep 16, 2015 at 14:01
  • can you make a simplified fiddle with the scenario that you tried with the service? Commented Sep 16, 2015 at 14:05
  • How you make the transition between modules? Are you using routes? Commented Sep 16, 2015 at 14:43
  • yup, let me know the best way Commented Sep 16, 2015 at 14:45

2 Answers 2

1

You need to set a dependency of M1 on M2. After that you will be able to access the services of M1 through which you can establish a communication between two controllers.

Sign up to request clarification or add additional context in comments.

1 Comment

tried by injecting M1 into M2, as when click it set the value on M1 service and redirect to home page and also M2 able to access the same service of function get but the value will be blank. I think when M2 calls service of M1 it create new instance and set value wont get. It will be helpful if you provie example via. plnkr
0

If it's on a separate pages, you either have to use the server to save the data on Page1 then load it on Page2 or use some sort of local storage on the client side(cookies, localStorage)

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.