Last active
July 13, 2016 21:50
-
-
Save maurotrigo/3e63e02ddad82f2f5b3e69d7bb621002 to your computer and use it in GitHub Desktop.
Ionic context menu as a service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ion-view view-title="{{ anyItem.name }}"> | |
<ion-nav-buttons side="right"> | |
<button class="button icon ion-more" ng-click="showOptions($event)"></button> <!-- IMPORTANT: include $event --> | |
</ion-nav-buttons> | |
<ion-content> | |
<!-- The rest of your template --> | |
</ion-content> | |
</ion-view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app.any_controller', [ | |
'services.special.app_menu' | |
]) | |
.controller('AssetsShowController', function($scope, AppMenuService, anyItem) { | |
// A random item | |
$scope.anyItem = anyItem; | |
var menuOptions = [ | |
{ | |
id: 'edit', | |
text: 'Edit', | |
callback: function() { | |
$state.go('^.edit', { anyItemId: anyItem.id }); | |
$scope.popover.hide(); | |
} | |
}, | |
{ | |
id: 'delete', | |
extraClass: 'assertive', // You can add a class to each of the menu's options | |
text: 'Delete', | |
callback: function() { | |
// Delete anyItem code goes here | |
$scope.popover.hide(); | |
} | |
}, | |
]; | |
$scope.popover = AppMenuService.createMenu({ | |
scope: $scope, | |
menuOptions: menuOptions | |
} | |
); | |
$scope.showOptions = function($event) { | |
// IMPORTANT: include $event parameter | |
$scope.popover.show($event); | |
}; | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment