我正在尝试使“Angular Material Design”菜单起作用,但是我似乎无法使用应该由ng-click注入(inject)的$ mdMenu。

我的HTML标记:

<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>

Angular Controller :
controllers.controller('menu', function menuControl($mdDialog) {
   var originatorEv;

   this.open = function($mdMenu, ev) {
     originatorEv = ev;
     $mdMenu.open(ev);
   };
});

Controller 已正确注入(inject),但运行时出现错误
TypeError: Cannot read property 'open' of undefined

有人知道如何解决此问题吗?
谢谢

最佳答案

代替 mdMenu ,传递 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

关于javascript - 将$ mdMenu注入(inject)范围。无法读取未定义的属性open(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42041868/

10-12 19:26