Menu bar is not working when using ng-repeat
I built the menu bar using ng-repeat angular directive. In this scenario menu bar is not working. But when i hard code without using ng-repeat, its working perfectly. Seems there will be a problem in menu bar when using ng-repeat.
Please provide a CodePen or Plunkr that demonstrates this issue. Here are some starter demo templates that you can use/fork:
- CodePen template: http://codepen.io/team/AngularMaterial/pen/BNYppz
- Plunkr template: http://plnkr.co/edit/yP0gB9iTacIQb48thud8?p=preview.
Here is the sample code: http://codepen.io/anon/pen/BoNGyN When i opened the level 1_1 menu and then try to open the level 1_2 menu, the previous didnt get close.
Here is another demo:
http://codepen.io/anon/pen/PPPpOJ
Please note: this also doesn't work when using ngInclude templates.
Hey guys, I fixed this locally with a small little function. They have a hide/close function in the controller, but it's not being exposed. So all I did was add the $mdMenu service to my directive, and access the hide function directly, and i just call my function before I call an individual open. Good hotfix until they patch the $mdOpenMenu function
$scope.closeOthers = function() {
$mdMenu.hide(null, { closeAll: true });
}
@christrude Can you please give me a sample layout in codepen. I can't able to reproduce
Here is an example Codepen that illustrates the reported issue.
After some research I noticed that it happens because md-menu directives use $scope.$emit for triggering the $mdMenuOpen event on which listen all md-menu instances. $emit triggers listeners on all parent scopes including the one on which the event is emitted. That means if all md-menu instances are on the same scope everything is fine but that is not the case with ng-repeat which creates new scope for each child.
I tried to implement @christrude's answer but I encountered a little problem. If you click menu1->menu2->menu1 again fast enought, it seems that menu1 will not be opened because it will still be hit by the close function.
@reylibutan The problem is that you are too fast. Gonna have to slow down a bit. ;-)
@Jayaraj8905 I'll try to get a codePen up for you today
+1
:+1: