0

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?

Sajeev Zacharias
  • 157
  • 1
  • 17

2 Answers2

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

Community
  • 1
  • 1
Jay Krish
  • 13
  • 3
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