I am facing an issue with sharing data between AngularJS controllers. The data is obtained through an http request, but when I try to access it in the controller, it returns null. Strangely, if I manually refresh through the UI, the data becomes available. I believe this problem is similar to what's described here, but none of the solutions have worked for me so far. You can check out the fiddle here.
Therefore, in my controller, I'm fetching the data using:
//myService.setName(); //commented as it breaks the code
This sets the value in the service, which can then be accessed using getName()
.
I've tried using $rootScope.$apply
as suggested in the link above, but unfortunately, I couldn't get it to work.