md-menu: not opening/closing menu and showing md-menu-content without clicking
So, I have this code that is very similar to the example on the documentation. The problem is there's no errors in my console and it's not working. It doesn't open or close the popup. Also, the content of md-menu-content is not hidden.
<md-menu>
<md-button ng-click="$mdOpenMenu()" class="md-icon-button" aria-label="Open sample menu">
<md-icon md-menu-origin md-svg-icon="./assets/images/sensor_icon.svg"></md-icon>
</md-button>
<md-menu-content>
<md-menu-item><md-button ng-click="vm.goThere()">Do Something</md-button></md-menu-item>
</md-menu-content>
</md-menu>
The menu is working correctly. http://codepen.io/anon/pen/BNwyrB
Nice. It must be something in my app then.
Update to version 0.10.0 to fix it
It still has a weird behaviour. It works perfectly when it's alone in the page. But sometimes the positioning of the popup menu is not done right. I'll check out the code to see what might be the problem.
Well, the menu component is added in v0.10.0. It won't be supported in the previous versions. https://github.com/angular/material/blob/master/CHANGELOG.md
Cool. But still, I have some problems with the positioning. I'll look into it now El 18/6/2015 13:30, "Mukil Elango" [email protected] escribió:
Well, the menu component is added in v0.10.0. It won't be supported in the previous versions. https://github.com/angular/material/blob/master/CHANGELOG.md
— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/3326#issuecomment-113120666.
So, something was conflicting with the popup menu appended to the body. In Angular Material, I changed the parent container to another element located inside the body that contains all my site and it's fixed.
The problem was that the 'top' css property of the popup menu appended was set to a large negative number(ex: -500px). It must be something on my site that mess up the calculations for the positioning but I guess it can happen to other sites so it's worth to look into
having same issue. top is very high negative value. @ruben1 How do you set the parent ?
https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L80 I changed it to the closest children of body and it calculated the top correctly.
btw, the large negative value on top is applied somehow here https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L101
Do you have any fixed elements on your page?
no i don't think so.
how do you pass the optional parent argument ?
I tried using
<md-menu parent="mySelector">
</md-menu>
but didn't worked.
Edit : peaked into source code and i think it is not exposed yet. Editing angular material's source code directly wont be possible in my environment.
I'm also having Ruben's problem, to show the menu I added a style, but I don't like it that way, I can't find what is interfering with the menu :disappointed:
I'm also facing the same issue, the popup position is not correct. Maybe we are missing some documentation here.
I tried with this < md-menu-content style="position: fixed; right:10px; top:64px;" > this helps me to show it, but all the options are shown in the same line, and it's awful this way,
fixed, at least for me, we had, for some strange reason, a copy of and old angular-material css :100:
Fixed on my side too :+1:
This was causing issues for me when I had a table with a good number of elements. Eventually when I do this:
//clamp(position);
el.css({
top: Math.abs(position.top) + 'px',
left: position.left + 'px'
});
Everything just works. I think there might be an issue in the clamp() logic.
https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L363
That fix worked for me, however some elements on the page still get the top: -500px property and get lost on the page. Does anyone have a solution for this?
I wasted one in trying to make mdMenu work but later I opened the codepen and pasted the code in my html template to surprisingly find it working. I noticed that it had $mdOpenMenu() while on the official documentation which is found here https://material.angularjs.org/latest/demo/menu has $mdMenu.open($event). Don't know but maybe this is due to some version difference. Hope you guys correct it.
@mohdsalmanshaikh63 you didn't provide any information on the version of AngularJS Material you are using. However, in this commit the $mdOpenMenu method was deprecated. This landed in 1.1.2. You should see a warning in the console if you use it due to: https://github.com/angular/material/blob/master/src/components/menu/js/menuController.js#L241-L245.