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?

Mistalis
18.3k14 gold badges78 silver badges97 bronze badges
asked Dec 14, 2016 at 10:42
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.

answered Dec 14, 2016 at 10:47

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
});
answered Dec 14, 2016 at 10:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.