0

In My Application I have two controllers .

Controller 1 | Controller 2


  1. From Controller 1 I am opening a menu on a button click and in a function defined a property say, this.isTelephoneMenuOpen = true;

Result : I am getting menu opened With two option edit and Remove.

2.From Controller 2 on click of edit I am opening a modal-overlay- working fine.

Issue :But not being able to hide the earlier opened menu.

How to use this property in another controller to hide the menu after modal gets opened?

1

2 Answers 2

0

Define the property as $rootScope as every application has a single root scope.

In Controller 1 - $rootScope.isTelephoneMenuOpen = true.

In Controller 2 - Set it to false after opening the menu $rootScope.isTelephoneMenuOpen = false.

Sign up to request clarification or add additional context in comments.

5 Comments

@lakshaya : Thanks Lakshya. Initially,$rootScope.isTelephoneMenuOpen = false ----->In Controller 1 Then, $rootScope.isTelephoneMenuOpen = true ----->In Controller 1 Result: opens the menu Need to make , $rootScope.isTelephoneMenuOpen = false----->In Controller 2 But Its taking false as intial value...so how to make it false again in controller 2 ?
u don't have to set $rootScope.isTelephoneMenuOpen = false as initial value. you should set it to false at the time when your model is opened and the menu should hide.
@lakshya:In My Project , Rootscope is not working :( Menu is not getting open when I put this property to Rootscope
have u defined $rootScope in your controller?
@lakshya: In First Controller : Getting the value true
0

One of the ways is broadcast event, have a look at the $rootScope.$broadcast().

For example, in the second controller you can broadcast an event

$rootScope.$broadcast('hideMenu', {hide: true})

and then catch it in the first controller

$scope.$on('hideMenu', function (event, data) {
  //code for hiding menu
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.