简体   繁体   English

md按钮内的可点击图标

[英]Clickable icon inside md-button

Is there a way to include a clickable icon inside a <md-button> without resizing the <md-button> to full width. 有没有一种方法可以在<md-button>包含可点击的图标,而无需将<md-button>调整为全角。

In my case, I want to add a close icon on the right of my buttons, and when the user click on this icon (which is inside the button), an action will be made, but not the one associated to the button. 就我而言,我想在按钮右侧添加一个关闭图标,当用户单击该图标(位于按钮内部)时,将执行一项操作,但不执行与该按钮关联的操作。

<md-button ng-click="customFilter('global')" class="md-raised md-primary">
    Global<md-icon md-svg-src='style/images/icons/ic_close_24px.svg'  
    style="color: red; width: 5%; height: 5%"></md-icon>
</md-button>

This add the icon inside the button, but the button takes then the full width. 这会将图标添加到按钮内部,但是按钮将占据整个宽度。

Ideally, the highlightning would differ between the button and the icon :hover but that's not my concern yet. 理想情况下,按钮和图标之间的突出显示会有所不同:hover但这不是我关心的问题。

Yes you can get this functionality. 是的,您可以获得此功能。 For styling your md-icon use "vw", this will make sure your icon gets width according to viewport. 要为md-icon设置样式,请使用“ vw”,以确保图标根据视口获得宽度。 1vw = 1% of viewport width 1vw =视口宽度的1%

Read more about vw here 在此处阅读有关大众的更多信息

Update your code as below 如下更新代码

<md-button ng-click="customFilter('global')" class="md-raised md-primary">
    Global
   <md-icon md-svg-src='style/images/icons/ic_close_24px.svg'  
       ng-click="action($event)" style="width:1.5vw"
   </md-icon>
</md-button>

Inside your controller you need to stop md-icon click event from propagating to parent md-button. 在控制器内部,您需要阻止md-icon click事件传播到父md-button。

$scope.action = function($event){
  //do your action 
  $event.preventDefault();
  $event.stopPropagation();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM