mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
/**
|
|
* @ngdoc directive
|
|
* @name menuClose
|
|
* @module ionic
|
|
* @restrict AC
|
|
*
|
|
* @description
|
|
* `menu-close` is an attribute directive that closes a currently opened side menu.
|
|
* Note that by default, navigation transitions will not animate between views when
|
|
* the menu is open. Additionally, this directive will reset the entering view's
|
|
* history stack, making the new page the root of the history stack. This is done
|
|
* to replicate the user experience seen in most side menu implementations, which is
|
|
* to not show the back button at the root of the stack and show only the
|
|
* menu button. We recommend that you also use the `enable-menu-with-back-views="false"`
|
|
* {@link ionic.directive:ionSideMenus} attribute when using the menuClose directive.
|
|
*
|
|
* @usage
|
|
* Below is an example of a link within a side menu. Tapping this link would
|
|
* automatically close the currently opened menu.
|
|
*
|
|
* ```html
|
|
* <a menu-close href="#/home" class="item">Home</a>
|
|
* ```
|
|
*/
|
|
IonicModule
|
|
.directive('menuClose', ['$ionicHistory', function($ionicHistory) {
|
|
return {
|
|
restrict: 'AC',
|
|
link: function($scope, $element) {
|
|
$element.bind('click', function() {
|
|
var sideMenuCtrl = $element.inheritedData('$ionSideMenusController');
|
|
if (sideMenuCtrl) {
|
|
$ionicHistory.nextViewOptions({
|
|
historyRoot: true,
|
|
disableAnimate: true,
|
|
expire: 300
|
|
});
|
|
sideMenuCtrl.close();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}]);
|