I have an ionic-side-menus directive for several pages, each with its own menu, can the content and menu page use the same controller in some way?
Asked
Active
Viewed 240 times
1 Answers
1
Yes you can, add the same controller in ui router
to the views you want to share the same controller with (app.js
)
Check out the following plnkr (standard side menu template from ionic)
#app.js
app
state (menu.html) and app.playlists
(playlists.html) shares the same controller (PlaylistCtrl
)
#controllers.js
in PlaylistCtrl
has two variables accessed by the side menu and the main page.
HTH

sameera207
- 16,547
- 19
- 87
- 152
-
But the problem would be the controller is loaded twice – user2412555 May 28 '15 at 08:25
-
@user2412555, If you want to share data between different controllers, they probably you might want to use a `service` have a look that this thread http://stackoverflow.com/questions/20181323/passing-data-between-controllers-in-angular-js – sameera207 May 28 '15 at 09:50
-
1Ye, I was forced to create a separated controller and communicate through service or broadcast message. – user2412555 May 28 '15 at 10:54