Reputation: 295
I have diferents controllers in my app.
admin.php:
<body ng-controller="AdminController as AdminCtrl">
player.php:
<body ng-controller="InteractiveController as interactCtrl">
these 2 .php documents have their respective admin.js and player.js with its .controller running correctly (I have more than these 2).
Now, I have the menu bar in menu.php, where I use in both admin.php and player.php documents, imported with:
<?php include('includes/menu.php'); ?>
So, if I want to use the values of each controller (admin.js and player.js) in the menu.php, how can I do it?
for example, I need to do this:
AdminCtrl.user.getUsername();
interactCtrl.user.getUsername();
But it is ridiculous because I would get js into an errors and if I had 500 controllers it wouldn't be recomended.
I thought that maybe I could do something similar to this:
<body ng-controller="AdminController as the_same_name">
<body ng-controller="InteractiveController as the_same_name">
but I thint that all my controllers with the same name won't be a good idea.
What do you think?
Thank you!
Upvotes: 0
Views: 43
Reputation: 1385
Basicly I recommend to store all the data you want to use cross-controller in one or more services, and then inject the service in your menubar controller. That way you can access the data you store in those services in your menubar.
Upvotes: 1