I am doing a project. Here I have a right sidebar which is to be shown in some pages and should not be shown in some other pages of the site. How this functionality can be achieved. Is it done by setting $rootscope variable in some page controllers and not in some other controllers?
Asked
Active
Viewed 29 times
0
-
Yes you can use $rootscope.showSidebar = true/false depending on the page. – Samir Das Apr 02 '15 at 09:11
2 Answers
0
From your page controller pass message to sidebar controller or main controller saying hide or show sidebar.
You can use emit and broad cast to pass massages between controller. Here is a good sample Working with $scope.$emit and $scope.$on
0
I would not use $scope.$emit
and $scope.$on
, I think a good way to deal with this is to have a parent controller, lets say a MainController
that shares it scope with both child controllers. Then from the child controllers you can call the parent one.
$emit
and $on
are quit performance heavy, especially when your application grows. Try to give it a minutes thought to figure out how you want to structure your code.

petur
- 1,366
- 3
- 21
- 42