I am trying to get the Angular Material Design menu to work but I don't seem to be able to use the $mdMenu that is supposed to be injected by the ng-click.
My HTML markup:
<div layout="column" layout-fill ng-controller="AuthControl">
<md-toolbar ng-controller="navigationControl">
<div ng-controller="menu as ctrl">
<md-menu>
<md-button class="md-icon-button" ng-click="ctrl.open($mdMenu, $event)">
<md-icon>menu</md-icon>
</md-button>
<md-menu-content width="4">
<md-menu-item>
<md-button>
<md-icon>account_circle</md-icon>
</md-button>
</md-menu-item>
</md-menu-content>
</md-menu>
</div>
</md-toolbar>
</div>
The Angular Controller:
controllers.controller('menu', function menuControl($mdDialog) {
var originatorEv;
this.open = function($mdMenu, ev) {
originatorEv = ev;
$mdMenu.open(ev);
};
});
The contoller gets injected properly but when I run I get the Error
TypeError: Cannot read property 'open' of undefined
Does anybody know how to fix this? Thanks
Instead of mdMenu
, pass mdOpenMenu
<md-button aria-label="menu" class="md-fab md-mini md-primary" ng-click="ctrl.openMenu($mdOpenMenu, $event)">
Controller:
this.openMenu = function($mdOpenMenu, ev) {
originatorEv = ev;
$mdOpenMenu(ev);
};
DEMO
"$mdOpenMenu" has been replaced by "$mdMenu.open" and is now deprecated. Use the latest version of Angular Material and it will work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With