Keep menu open after selecting a item in angular

时间:2016-04-25 09:01:11

标签: angularjs angular-material

My menu is closing after I click on my toggleSharebutton. How can i prevent this. I use angularJS with Angular material

Here is my code:

 <md-menu>
        <md-button ng-click="$mdOpenMenu()">
        </md-button>
        <md-menu-content>
            <md-menu-item>
              <md-button ng-click="toggleShare()"> 
              </md-button>
            </md-menu-item>
        </md-menu-content>
    </md-menu>

2 个答案:

答案 0 :(得分:3)

您可以使用[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] public abstract class BaseController : Controller { // no cache by default } public class MyController : BaseController { [OutputCache(NoStore = false, Duration = 60, VaryByParam = "searchText", Location = OutputCacheLocation.Any)] public PartialViewResult Test(string searchText) { // this method cached ok } } 属性停止菜单关闭,如offical doc中所示。以下是编写代码的方法

md-prevent-menu-close

以下是使用此方法获得所需结果的工作示例。 http://codepen.io/next1/pen/aNadYR

答案 1 :(得分:2)

上面的答案应该是接受的答案,但您也可以使用ngMouseup代替ngClick,它的工作原理相同:)

<md-menu>
  <md-button ng-click="$mdOpenMenu()">
  </md-button>
  <md-menu-content>
    <md-menu-item>
      <md-button ng-mouseup="toggleShare()"> 
       </md-button>
    </md-menu-item>
  </md-menu-content>
</md-menu>