javascript 如何从 Ionic 中的图标按钮显示下拉菜单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29708073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display dropdown menu from an icon button in Ionic?
提问by David Prieto
I'm trying to create a dropdown menu with the options "share" and "delete" that displays from an icon button, but Ionic doesn't support it out of the box.
我正在尝试创建一个下拉菜单,其中包含从图标按钮显示的“共享”和“删除”选项,但 Ionic 不支持开箱即用。
The button in question is like this:
有问题的按钮是这样的:
<button class="button button-icon icon ion-navicon-round" ng-click="show()">
</button>
I checked the question (ionic how to display a dropdown of choices on button click) but it didn't help.
我检查了这个问题(ionic how to display a dropdown of options on button click)但它没有帮助。
Maybe I need some Angular.js trick? I'm new in both Angular.js and Ionic framework.
也许我需要一些 Angular.js 技巧?我是 Angular.js 和 Ionic 框架的新手。
回答by aorfevre
What you are looking for is component $ionicPopover
您正在寻找的是组件$ionicPopover
First create your component
首先创建你的组件
$ionicPopover.fromTemplateUrl('settings.html', {
scope: $rootScope,
}).then(function(popover) {
$scope.popup = popover;
});
Then you can show it from ng-click of your button
然后你可以通过点击你的按钮来显示它
$scope.show= function($event) {
$scope.popup.show($event);
};
Ng-click of your function shall be updated also to send the $event paramenter
您的函数的 Ng-click 也应更新以发送 $event 参数
ng-click="show($event)"