I want to use a side menu:
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-positive" align-title="center">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" width="300">
<ion-content>
<div class="list">
<a class="item item-icon-left left no-border" ui-sref="app.home" menu-close>
<i class="icon menu-icon ion-home"></i>
<h2>Hom</h2>
</a>
<a class="item item-icon-left left no-border" ui-sref="app.account" menu-close>
<i class="icon menu-icon ion-person"></i>
<h2>Item 1</h2>
</a>
<a class="item item-icon-left left no-border" ui-sref="app.orders" menu-close>
<i class="icon menu-icon ion-android-list"></i>
<h2>Item 2</h2>
</a>
</div>
</ion-content>
</ion-side-menu>
</ion-side-menus>
As you can see im using the menu-close directive because i want the side menu to hide when i clicked on an item. The problem is that using this menu-close directive the state of the selected item is set to be the root. That means if i press the back button i wont get navigated back.
How can i close the menu when i click on an item without setting the selected view to be the root of the state?
I solve this doing the following in my menu item controllers:
angular.module("App.Home", [])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state("app.home", {
url: "/home",
views: {
"menuContent": {
templateUrl: "templates/menu_home.html",
controller: "HomeController"
}
}
});
})
.controller("HomeController", function($scope, $ionicSideMenuDelegate) {
$ionicSideMenuDelegate.toggleLeft(false);
});
EDIT
The following is an even better solution:
Just add a controller to your side menu:
<ion-side-menu side="left" width="300" ng-controller="MenuController">
And this to your controller:
angular.module("App.Menu")
.controller("MenuController", function($scope, $ionicSideMenuDelegate) {
$scope.toggleMenu = function() {
if($ionicSideMenuDelegate.isOpenLeft()) {
$ionicSideMenuDelegate.toggleLeft(false);
} else {
$ionicSideMenuDelegate.toggleLeft(true);
}
}
});
In your menu items you just need to call:
<a class="item item-icon-left item-left item-no-border" ui-sref="app.home" ng-click="toggleMenu()">
and everything is working like a charm.
Related
I want to remove the back button from the navigation pane in ionic .
I tried using hide-back-button , $ionicHistory , $ionicHandleDelegate but it do=id not serve my purpose. I just dont want to navigate to previous page using "Back" because the menu button serves the purpose.
My html goes like this
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Left</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close href="#/app/home">
Home
</ion-item>
<div ng-repeat = "opt in menuOptions">
<ion-item ng-click = "toggleOptions(opt)">
{{opt.name}}
</ion-item>
<ion-item menu-close ng-repeat = "item in opt.items" ng-show = "opt.show" ng-click = "toggleSubOptions(item)">
{{item.itemName}}
</ion-item>
</div>
<ion-item menu-close href="#" ui-sref="app.resetpass">
Reset Password
</ion-item>
<ion-item menu-close href="#" ng-click="logout()">
Logout
</ion-item>
</ion-list>
</ion-content>
My Controller goes this way
serveApp.controller('AppCtrl', ['$scope','$state','$auth',function($scope,$state,$auth) {
console.log("App Ctrl");
$scope.menuOptions = [{
{
name : 'Opt2',
show : false,
items : [],
goTo: "app.page2"
},
{
name : 'Opt2',
show : false,
items : [],
goTo: "app.page2"
}
];
$scope.toggleOptions = function (option){
if(option.items.length != 0){
//console.log("suboption",option)
option.show = !option.show;
} else {
//console.log("no sub")
$state.go(option.goTo);
}
};
Hi Developing an Mobile app using Ionic Framework.
I know its very basic question but i m new to this.
In the Index.html is having two buttons 1 is for Login and other for SignUp
index.html
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<script src="js/services.js"></script>
<script src="js/routes.js"></script>
</head>
<body ng-app="starter" ng-controller="MainCtrl">
<ion-pane>
<div class="bar bar-header bar-calm">
<h1 class="title">Heading</h1>
</div>
<ion-content paging="true" class="has-header" >
<div>
<img src="img/Logo.jpg" width="100%" height="auto" style="display:block;margin-left:auto;margin-right:auto;" />
<img src="img/Team.jpg" width="70%" height="auto" style="display:block;margin-left:auto;margin-right:auto;" />
</div>
<div ng-cntroller="loginCtrl">
<button id="btnLogin" class="icon icon-right ion-log-in left button button-positive button-block " style="border-radius:15px 15px 15px 15px;" ng-click="login()">Login</button>
</div>
<div ng-cntroller="signupCtrl">
<button id="btnSignUp" class="button button-positive button-block icon icon-right ion-person left" style="border-radius:15px 15px 15px 15px;">SignUp</button>
</div>
<div class="bar bar-footer bar-calm">
<div class="title">Copyright <strong>#</strong></label>
</div>
</ion-content>
</ion-pane>
On login click it open the Login.html page similar way click on sign up it open Signup.html
app.js
angular.module('starter', ['ionic','starter.controllers','starter.routes','starter.services','starter.directives'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(cordova.platformId === 'ios' && window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
routes.js
var app = angular.module('starter', [])
app.config(function($stateProvider,$urlRouteProvider){
$stateProvider
.state('text', {
url: '/page1',
templateUrl: 'templates/text.html',
controller: 'textCtrl'
});
.state('login', {
url: '/page2',
templateUrl: 'templates/login.html',
controller: 'loginCtrl'
});
.state('signUp', {
url: '/page3',
templateUrl: 'templates/signup.html',
controller: 'signupCtrl'
});
.state('chats', {
url: '/page4',
templateUrl: 'templates/chats.html',
controller: 'chatsCtrl'
});
$urlRouteProvider.otherwise('/page1')
});
controllers.js
var app = angular.module('starter')
app.controller('textCtrl',function($scope){
});
app.controller('loginCtrl', function ($scope) {
$scope.login = function(){
alert("Hi")};
});
app.controller('signUpCtrl', function ($scope) {
});
app.controller('chatsCtrl', function ($scope) {
});
login.html
<ion-view title="Login" id="page2" class=" ">
<ion-content padding="true" class="has-header">
<form id="login-form1" class="list ">
<ion-list id="login-list1" class=" ">
<label class="item item-input " id="login-input1">
<span class="input-label">Username</span>
<input type="text" placeholder="">
</label>
<label class="item item-input " id="login-input2">
<span class="input-label">Password</span>
<input type="password" placeholder="">
</label>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<a ui-sref="chats" id="login-button3" style="border-radius:15px 15px 15px 15px;" class=" button button-calm button-block ">Log in</a>
<a ui-sref="signup" id="login-button4" class=" button button-positive button-block button-clear ">Or create an account</a>
</form>
</ion-content>
</ion-view>
You need to define what the login button should do. Two ways to go
Either do
<button id="btnLogin" ui-sref="login">Login</button>
or do this on ng-click of the button like
$scope.login = function(){
$state.go('login');
};
Make sure $state is injected into your controller.
using this link will help to solve my issue
http://www.joshmorony.com/user-authentication-with-ionic-and-parse-part-1-email-login/
I have tried several code samples to get a back button in my home page. I couldnt see the nav back button. Where i am wrong?
<ion-side-menus enable-menu-with-back-views="true">
<ion-nav-bar class="bar-dark">
<ion-nav-back-button class="button-clear">
<i class="button button-icon my-back-button"></i>
</ion-nav-back-button>
</ion-nav-bar>
<ion-side-menu-content>
<ion-nav-view></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="right">
<ion-header-bar class="dark-bg expanded">
<span>R</span>
<p align="center"> My App</p>
</ion-header-bar>
<ion-content class="stable-bg has-expanded-header">
<ion-list>
<ion-item nav-clear menu-close ui-sref="app.settings">
Settings
</ion-item>
<ion-item nav-clear menu-close ui-sref="app.profile">
Profile
</ion-item>
<ion-item nav-clear menu-close ui-sref="app.logout">
Log out
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
Home page code
<ion-view title="Home">
<ion-content>
<div class="list card">
<a class="item item-icon-left assertive" ui-sref="makerequest">
<i class="icon ion-ios-list-outline"></i>
Make New Request
</a>
<a class="item item-icon-left assertive" ui-sref="viewrequest">
<i class="icon ion-ios-copy"></i>
View Request
</a>
</div>
</ion-content>
</ion-view>
Added my home page code above.
Regards,
Sabarisri
I've a simple application with a side menu where you can navigate to different views. If I click on an item I get redirected to that view but the back button doesn't show up, which seems to be the default behaviour.
Is there a build in way to show the back button on side menu navigation?
I've found this codepen on the ionic forum which uses the same basic structure as I do: http://codepen.io/mhartington/pen/azwojR
This is my complete menu:
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content id="header-wrapper">
<div id="logoHeader" class="bar bar-header">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
<img src="img/rg-gunz-christmas.png" />
</div>
<ion-nav-bar id="header" class="bar bar-header">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu id="menu" side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Menu</h1>
</ion-header-bar>
<ion-content>
<div class="account">
<img ng-src="{{account.AvatarUrl}}" class="avatar"/>
<div class="username">{{account.UserID}}</div>
</div>
<ion-list>
<ion-item menu-close href="#/app/main">
<i class="icon ion-home"></i> <span class="padding-left">Home</span>
</ion-item>
<ion-item menu-close href="#/app/login" ng-show="!account">
<i class="icon ion-log-in"></i> <span class="padding-left">Login</span>
</ion-item>
<ion-item menu-close href="#/app/register" ng-show="!account">
<i class="icon ion-person"></i> <span class="padding-left">Register</span>
</ion-item>
<ion-item menu-close href="#/app/individualRanking">
<i class="icon ion-arrow-graph-up-right"></i> <span class="padding-left">Individual ranking</span>
</ion-item>
<ion-item menu-close href="#/app/clanRanking">
<i class="icon ion-ios-bolt"></i> <span class="padding-left">Clan ranking</span>
</ion-item>
<ion-item menu-close href="#/app/statistics">
<i class="icon ion-stats-bars"></i> <span class="padding-left">Statistics</span>
</ion-item>
<div class="item item-divider" ng-show="account">
Account
</div>
<ion-item menu-close href="#/app/playlists" ng-show="account">
<i class="icon ion-settings"></i> <span class="padding-left">Settings</span>
</ion-item>
<ion-item menu-close href="#/app/playlists" ng-show="account">
<i class="icon ion-log-out"></i> <span class="padding-left">Log out</span>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
its hard to predict here.just check may be some other view is override in the view which is opening.
i had same problem.may be this could help you.
place ion-nav-bar in particular view, where u want to show back button!
<ion-view view-title="Order Details">
<ion-nav-bar class=" dark">
<ion-nav-back-button class="button-clear button-dark stable ">
<i class="ion-arrow-left-c stable"></i> Back
</ion-nav-back-button>
</ion-nav-bar>
<ion-content class="content-stable"></ion-content>
</ion-view>
Try this code: You can add this class ion-ios-arrow-back or ion-ios7-arrow-back
<ion-side-menu-content >
<ion-nav-bar class="bar-energized nav-title-slide-ios7">
<ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="link" animation="slide-left-right"></ion-nav-view>
</ion-side-menu-content>
I have the following code:
personal-info.html
<ion-view view-title="Personal Information" can-swipe-back="true">
<ion-nav-buttons side="left">
<button class="button button-icon icon ion-ios-arrow-left" ng-click="doTheBack()" nav-direction="back"></button>
</ion-nav-buttons>
<ion-content class="padding">
<div class="list card">
<div class="item item-divider">Recent Updates</div>
<div class="item item-body">
<div>
There is a fire in <b>sector 3</b>
</div>
</div>
</div>
</ion-content>
</ion-view>
and my controller
.controller('PersonalInfoCtrl', function($scope) {
$scope.doTheBack = function() {
window.history.back();
};
});
I want to enable the swipe back feature I tried by putting can-swipe-back="true" inside <ion-view> tag but it didn't help at all. Also I have checked a lot of documentation as well as this question How do you "Swipe to go back" in Ionic? but it seems that swipe back feature is not enabled for my application.
The way I implemented it was through $ionicNavBarDelegate.
In HTML:
<ion-view view-title="Personal Information">
<ion-content on-swipe-right="swipe('right')" class="padding">
<div class="list card">
<div class="item item-divider">Recent Updates</div>
<div class="item item-body">
<div>
There is a fire in <b>sector 3</b>
</div>
</div>
</div>
</ion-content>
</ion-view>
In controller:
$scope.swipe = function (direction) {
if(direction == 'right')
$ionicNavBarDelegate.back();
}
Make sure to include $ionicNavBarDelegate in your controller header.
If that doesn't work, take a look at http://forum.ionicframework.com/t/any-sample-code-on-how-to-use-swipe-to-go-back/19122/13. Swipe-to-go-back seems to work by default since RC0 as demonstrated by http://codepen.io/mhartington/pen/RNqpJp.