Ionic routing to sub-page - angularjs

I'm having trouble setting up ionic to do proper routing. Want it to upen another page and have the back button displayed.
routes.js
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
// Learn more here: https://github.com/angular-ui/ui-router
$stateProvider
.state('records', {
url: '/records',
templateUrl: 'templates/records.html',
controller: 'RecordsCtrl'
})
.state('records-newRecord', {
url: '/records/newRecord',
templateUrl: 'templates/newRecord.html',
controller: 'newRecordCtrl'
})
$urlRouterProvider.otherwise('/records')
});
records.html
<ion-view title="Records" id="main">
<ion-nav-bar>
<!-- ADD BUTTON-->
<ion-nav-buttons side="primary">
<button class="button button-icon ion-plus-circled" href="#/records/newRecord"></button>
</ion-nav-buttons>
<!--SEARCH BUTTON-->
<ion-nav-buttons side="secondary">
<button class="button button-icon ion-search" ng-click="toggleSearchBar()"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content padding="true" class="has-header">
<!-- SEARCH BAR -->
<div ng-show="showSearchBar">
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" placeholder="">
</label>
</div>
<!-- LIST OF RECORDS -->
<form class="list">
<ion-item class="item-thumbnail-left">
<img src="img/pQqcmU4fR8GSvP092hQN_Lockreal72.jpg">
<h2>Temp. Logger PC4</h2>
<p>SN C001517 A</p>
</ion-item>
</form>
</ion-content>
</ion-view>
The problem is that it does not redirect.
I had another version that did, but it didn't show the back button or if it did then the header was empty. So changed the code to what it is now.
What am I doing wrong here?
BTW: Is there a way to prompt the user if the back button is pressed. Like prompting and asking "Sure you wanna leave?"

On the new Record page try adding the ion-nav-back-button markup in ion-nav-bar that should add a backbutton you can also check the docs for ways to customise the button
<ion-nav-bar>
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
and about adding a prompt you will need to use the custom method instead
Template
<ion-nav-bar ng-controller="MyCtrl">
<ion-nav-back-button class="button-clear"
ng-click="myGoBack()">
<i class="ion-arrow-left-c"></i> Back
</ion-nav-back-button>
</ion-nav-bar>
Controller
function MyCtrl($scope, $ionicHistory, $ionicPopup) {
$scope.myGoBack = function () {
$ionicPopup.confirm({
title: 'Leaving',
template: 'Are you sure you want to leave?'
}).then(function (res) {
if (res) {
$ionicHistory.goBack();
} else {
console.log('You are not sure');
}
});
};
}

I found the that using the ui-sref= is a simple solution from this post.
<ion-view view-title="Records" id="main">
<ion-nav-bar class="bar-stable">
<!-- ADD BUTTON-->
<ion-nav-buttons side="primary">
<button class="button button-icon ion-plus-circled" ui-sref="newrecord"></button>
</ion-nav-buttons>
...
Made the routes.js more simple
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
// Learn more here: https://github.com/angular-ui/ui-router
$stateProvider
.state('records', {
url: '/records',
templateUrl: 'templates/records.html',
controller: 'RecordsCtrl'
})
.state('newrecord', {
url: '/newrecord',
templateUrl: 'templates/newRecord.html',
controller: 'newRecordCtrl'
})
$urlRouterProvider.otherwise('/records')
});

Related

ionic - unable to print title on navbar

I am working with angular and ionic and i'm currently not able to print ANY title in the navbar.
I have a quite complex setup with multiple nested views.
Here's the list of states:
state('app', {
cache: false,
url: '/app',
abstract: true,
templateUrl: './sections/menu/menu.tpl.html',
controller: 'menuCtrl'
}).state('app.home', {
url: '/home',
views: {
'appContent': {
templateUrl: './sections/menu/pageViewsContainer.tpl.html',
controller: 'homeCTRL'
},
'Details#app.home': {
templateUrl: './sections/home/home.tpl.html'
},
'List#app.home': {
templateUrl: './sections/List/List.tpl.html'
}
}
}).state('app.details', {
name: 'appDetails',
url: '/:ID',
views: {
'appContent': {
templateUrl: './sections/menu/pageViewsContainer.tpl.html',
controller: 'DetailsCtrl'
},
'zoneDetails#app.details': {
templateUrl: './sections/Details/Details/details.tpl.html'
},
'zoneList#app.details': {
templateUrl: './sections/List/List.tpl.html'
}
}
});
My main (abstract) state is app and uses menu.tpl.html which looks like this:
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content class="custom-central-content">
<ion-nav-bar class="bar-calm custom-header-bar">
<ion-nav-buttons side="left">
<!--<button class="button button-icon button-clear ion-home" menu-toggle="left"></button>-->
<button class="button button-icon button-clear ion-home" ui-sref="app.myHouse" id="AppMenuLeftIcon"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-navicon" menu-toggle="right" id="AppMenuRightIcon"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-view ui-view="appContent"></ion-view>
</ion-side-menu-content>
<ion-side-menu side="right">
<ion-header-bar class="bar-dark">
.....
inside <ion-view ui-view="appContent"></ion-view> I am using the template from pageViewsContainer.tpl.html which is:
<ion-view>
<ion-content class="hg-split-page-container">
<div ui-view="List" class="hg-split-page-zone-list has-header" nav-transition="none"></div>
<ion-nav-view name="Details" class="hg-split-page-zone-details"></ion-nav-view>
</ion-content>
</ion-view>
and then inside both Details and List I am printing the two views I need.
The problem is that I need to be able to set a static title for the main (home) page, but then dynamically change it when I go inside Details with the name of the page from my scope.
The problem is that I am not able to print ANY title (plain text, not scope) in any way.
I tried with (in pageViewsContainer.tpl.html):
<ion-view>
<ion-nav-title>View 1</ion-nav-title>
<ion-content class="hg-split-page-container">
<div ui-view="List" class="hg-split-page-zone-list has-header" nav-transition="none"></div>
<ion-nav-view name="Details" class="hg-split-page-zone-details"></ion-nav-view>
</ion-content>
</ion-view>
<ion-view view-title="View 1">
<ion-content class="hg-split-page-container">
<div ui-view="List" class="hg-split-page-zone-list has-header" nav-transition="none"></div>
<ion-nav-view name="Details" class="hg-split-page-zone-details"></ion-nav-view>
</ion-content>
</ion-view>
as well as (inside details template):
<ion-view>
<ion-nav-title>View 1</ion-nav-title>
<ion-content class="has-footer has-header">
...
<ion-view view-title="View 1">
<ion-content class="has-footer has-header">
...
But nothing worked.
Suggestions?
Try adding the title command inside header-bar
<ion-view>
<ion-header-bar class="bar-stable">
<h1 class="title">View 1</h1>
</ion-header-bar>
<ion-view>
or try
<ion-view>
<div class="bar bar-header browse-header" align-title="center">
<h1 class="title">View 1</h1>
</div>
<ion-content class="has-header">
</ion-content>
</ion-view>
It turned out I had to change quite a bit on my navigation, as I was using the nested views, parent, childs in a completely wrong way. It's working fine now.
Also, if, for some reasons, the title navbar it's still not displayed, you can force it using this in the controller (coffeescript):
# This should show the navabar everytime the view is entered
$scope.$on '$ionicView.enter', () ->
$ionicNavBarDelegate.showBar true

Ionic button ng-click

I do have a different button on my first page.I just want to move to respective page on clicking to each button.However this is not working.I am new to ionic. Plz help.
Here is my controller.js
`angular.module('starter.controllers', [])
.controller('TutorialsCtrl', function($scope) {})
.controller('AndroidCtrl', function($scope,$state) {
$scope.create = function () {
$state.go('templates/android');
};
});`
This is my app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
// Each tab has its own nav history stack:
.state('tab.tutorials', {
url: '/tutorials',
views: {
'tab-tutorials': {
templateUrl: 'templates/tutorials.html',
controller: 'TutorialsCtrl'
}
}
})
.state('tab.android',{
url:'/tutorials/:tutorialId',
views:{
'tab-tutorials':{
templateUrl:'templates/android.html',
controller:'AndroidCtrl'
}
}
})
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/tutorials');
});
here is my tutorials.html page
<ion-view view-title="Tutorials">
<ion-content class="padding">
<div class="background">
<button class="button button-outline button-positive myandroid" ng-click="create()">
<i class="icon ion-social-android home"></i>
<p>Android</p>
</button>
</div>
</ion-content>
</ion-view>
I want to navigate from tutorials.html to android.html.I do have a blank android.html page at this instant
Instead of button use a(anchor) as you wanted to change the state(route) of your application. And on each anchor you could use ui-sref directive with respective stateName, so that will create create a required href tag over there.
Markup
<ion-view view-title="Tutorials">
<ion-content class="padding">
<div class="background">
<a class="button button-outline button-positive myandroid" ui-sref="tab.tutorials">
<i class="icon ion-social-android home"></i>
<p>Android</p>
</button>
</div>
</ion-content>
</ion-view>
With $state.go() you can go to a state, not to a template as you did.
$scope.create = function () {
$state.go('tab.android');
};

Adding slideshow to the ionic side menu starter app is not working

I am a novice to ionic and AngularJS so suspect I am doing something stupid but can't for the life of me work out what. I am using the ionic starter template for a side menu app. I have added another menu item for a 'new home' page. Into this page I have added some code from the ionic code pen example for an introduction slide show. Unfortunately I only get an empty page rather than the slide show.
My home.html template looks like this:
<script id="templates/home.html" type="text/ng-template">
<ion-view view-title="Intro">
<ion-nav-buttons side="left">
<button class="button button-positive button-clear no-animation" ng-click="startApp()" ng-show="!slideIndex">
Skip Intro
</button>
<button class="button button-positive button-clear no-animation" ng-click="previous()" ng-show="slideIndex > 0">
Previous Slide
</button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-positive button-clear no-animation" ng-click="next()" ng-show="slideIndex != 2">
Next
</button>
<button class="button button-positive button-clear no-animation" ng-click="startApp()" ng-show="slideIndex == 2">
Start using MyApp
</button>
</ion-nav-buttons>
<ion-slide-box on-slide-changed="slideChanged(index)">
<ion-slide>
<h3>Thank you for choosing the Awesome App!</h3>
<div id="logo">
<img src="http://code.ionicframework.com/assets/img/app_icon.png">
</div>
<p>
We've worked super hard to make you happy.
</p>
<p>
But if you are angry, too bad.
</p>
</ion-slide>
<ion-slide>
<h3>Using Awesome</h3>
<div id="list">
<h5>Just three steps:</h5>
<ol>
<li>Be awesome</li>
<li>Stay awesome</li>
<li>There is no step 3</li>
</ol>
</div>
</ion-slide>
<ion-slide>
<h3>Any questions?</h3>
<p>
Too bad!
</p>
</ion-slide>
</ion-slide-box>
</ion-view>
My app.js looks like this:
angular.module('starter', ['ionic', 'starter.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
// :NEW: Added stuff to show a home page
.state('app.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'IntroCtrl'
}
}
})
.state('app.search', {
url: '/search',
views: {
'menuContent': {
templateUrl: 'templates/search.html'
}
}
})
.state('app.browse', {
url: '/browse',
views: {
'menuContent': {
templateUrl: 'templates/browse.html'
}
}
})
.state('app.playlists', {
url: '/playlists',
views: {
'menuContent': {
templateUrl: 'templates/playlists.html',
controller: 'PlaylistsCtrl'
}
}
})
.state('app.single', {
url: '/playlists/:playlistId',
views: {
'menuContent': {
templateUrl: 'templates/playlist.html',
controller: 'PlaylistCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/playlists');
});
My controllers.js looks like this:
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//$scope.$on('$ionicView.enter', function(e) {
//});
// Form data for the login modal
$scope.loginData = {};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
};
// Open the login modal
$scope.login = function() {
$scope.modal.show();
};
// Perform the login action when the user submits the login form
$scope.doLogin = function() {
console.log('Doing login', $scope.loginData);
// Simulate a login delay. Remove this and replace with your login
// code if using a login system
$timeout(function() {
$scope.closeLogin();
}, 1000);
};
})
.controller('IntroCtrl', function($scope, $state, $ionicSlideBoxDelegate) {
$scope.next = function() {
$ionicSlideBoxDelegate.next();
};
$scope.previous = function() {
$ionicSlideBoxDelegate.previous();
};
// Called each time the slide changes
$scope.slideChanged = function(index) {
$scope.slideIndex = index;
};
})
.controller('PlaylistsCtrl', function($scope) {
$scope.playlists = [
{ title: 'Reggae', id: 1 },
{ title: 'Chill', id: 2 },
{ title: 'Dubstep', id: 3 },
{ title: 'Indie', id: 4 },
{ title: 'Rap', id: 5 },
{ title: 'Cowbell', id: 6 }
];
})
.controller('PlaylistCtrl', function($scope, $stateParams) {
});
The menu.html looks 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 ng-click="login()">
Login
</ion-item>
<ion-item menu-close href="#/app/search">
Search
</ion-item>
<ion-item menu-close href="#/app/browse">
Browse
</ion-item>
<ion-item menu-close href="#/app/playlists">
Playlists
</ion-item>
<!-- :NEW: Added New Home menu item -->
<ion-item menu-close href="#/app/home">
New Home
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
When I run this app, open the menu, and select the New Home menu option the home.html page does not show properly, it is blank. I am sure I must be doing something stupid here.
I found my stupidity!
I had copied a line from the codepen example that wasn't needed and broke my code. Removing the following code from the home.html fixes the problem.
<script id="templates/home.html" type="text/ng-template">

Sharing multiple views and controllers using "ion" view calls in Ionic Project

I've been stuck on this issue for a week now and I feel like I understood 'ui-router' and 'ionic's' view routing but this seems not to be the case.
I've seen numerous examples how the view works but now as my build is larger, the examples I've seen are too simplistic for my project as my project has views for both a side menu, tabs, and each tabs content.
My issue:
I am holding more than one view with different controllers inside of my tabs. I'm working with a leaflet map and a drop down list that will be populated with my locations and I got both to work. However, the views are making weird calls. Anytime I select the leaflet map it pushes my "Discover List" (in my discover-home.html) button under my apps ion-nav-bar in my menu.html. In addition, you can see that this list view is in-between my map and the zoom icons and if do not touch my map and I switch tabs and come back I cannot open the list again.
I think the question's I need to ask to understand my problem are
1. What is the correct way to navigate in a multi-viewed applications using ionic's view navigation?
2. Why does changing views disable other controllers from being called again?
3. What are some of the best practices?
This is what I'm dealing with. Any help would be appreciated.
my tab view inside discover-home.html
Sidebar view inside menu.html
List Display inside discover-home.html
discover list in discover-home.html hidden under ion-nav-bar in menu.html
Here's my code snippets
index.html
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
</body>
discover-tabs-controller.html
This controls the tabs views (one of which is discover-home.html)
<ion-view>
<div class="tabs-striped tabs-top tabs-background-positive tabs-color-light">
<ion-tabs class="tabs-positive tabs-icon-only" >
<ion-content has-subheader="true"></ion-content>
<!--HOME TAB [OPEN]-->
<ion-tab title="Discover" icon-on="icon ion-home" icon-off="icon ion-home"
href="#/app/discover/home">
<ion-nav-view cache-view="true" name="home-tab"></ion-nav-view>
<!-- View For Home.html -->
</ion-tab>
<!--HOME TAB [CLOSED]-->
<!--MORE TABS HERE-->
</ion-content>
</ion-tabs>
</div>
</ion-view>
Discover-home.html
<ion-view view-title="Home">
<!--SUBHEADER BUTTON: DISPLAY LISTVIEW -->
<div ng-controller="FrostCtrl" class="bar bar-subheader button bar-balanced" ng-click="pushFrost()">
<h2 class="title">{{title}} List</h2>
</div>
<!--DISPLAY OVERLAY WITH LIST-->
<ion-pane ng-controller="OverlayCtrl" class="dark-overlay" ng-show="showOverlay">
<ion-content class="has-subheader">
<button class="button button-block button-outline button-balanced" ng-click="hideFrost()">Dismiss
</button>
<ion-list>
<ion-item ng-repeat="item in items" class="dark-item">
{{item.text}}
</ion-item>
</ion-list>
</ion-content>
</ion-pane>
<!--LEAFLET MAP -->
<leaflet class="has-subheader padding"center="nassau" paths="paths" tiles="tiles" markers="markers" defaults="defaults">
</leaflet>
</ion-view>
controller.js
angular.module('starter.controllers', [])
...
// #######| LEAFLET MAP |#######
.controller('ActivityCntl', [ '$scope', 'leafletData', function($scope, leafletData) {
var tileSource = {
onlineTiles: {
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
},
};
angular.extend($scope, {
nassau: {
lat: 25.074521,
lng: -77.318191,
zoom: 13
.........
});
}])
// #######| SHOW OVERLAY |#######
.controller('FrostCtrl', ['$scope', '$rootScope', '$compile', function($scope, $rootScope, $compile) {
$scope.pushFrost = function() {
var el = angular.element(document.getElementById('myPane'));
el.attr('frost', '');
el = $compile(el)($scope);
$rootScope.showOverlay = true;
};
}])
//#######| DISPLAYS CONTENTS |##########
.controller('OverlayCtrl', function($scope, $rootScope, $compile) {
$scope.items = [];
for(var i = 0; i < 5; i++) {
$scope.items.push({
text: 'Whatever ' + (i+1)
});
}
$scope.hideFrost = function() {
$rootScope.showOverlay = false;
var el = angular.element(document.getElementById('myPane'));
};
})
app.js
config(['$stateProvider', '$urlRouterProvider','$locationProvider',function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('app', {
name: 'app',
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.discover', {
name: 'app.discover',
url: "/discover",
views: {
'menuContent': {
templateUrl: "templates/discover-tabs-controller.html"
}
}
})
// for my discover-home.html
.state('app.discover.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "templates/discover-tabs/discover-home.html",
controller: 'ActivityCntl'
},
'discover-home-listview': {
templateUrl: "templates/discover-tabs/discover-home.html",
}
}
})
menu
This controls the sidemenu items
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
//IT GETS PUSHED UNDER THIS
<ion-nav-bar class="bar-calm">
<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">MYApps</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close ng-click="login()">
<i class="icon ion-person"></i>
Login
</ion-item>
<ion-item menu-close href="#/app/discover">
<i class="icon ion-location"></i>
Discover
</ion-item>
<ion-item menu-close href="#/app/map">
<i class="icon ion-map"></i>
Map
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>

Ionic - How to remove sidemenu on login page only?

I need to remove sidemenu only on my login page. Otherwise remain. How it can be done? I'm using command ionic ionic start myApp sidemenu to create the project.
app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('login', {
url: "/login",
templateUrl: "templates/login.html",
controller: 'LoginCtrl'
})
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.search', {
url: "/search",
views: {
'menuContent' :{
templateUrl: "templates/search.html"
}
}
})
login page
<ion-view title="Login">
<ion-content>
<div class="list">
<label class="item">
<button class="button button-block button-positive" type="submit" ng-click="login()">Log in</button>
</label>
</div>
</ion-content>
</div>
You can disable/enable sidemenu at any time at any page by calling
$ionicSideMenuDelegate.canDragContent(false)
e.g:
angular.module('ABC').controller('xyzCtrl', function($scope, $ionicSideMenuDelegate) {
$ionicSideMenuDelegate.canDragContent(false)
});
**Ionic 2**
import { MenuController } from 'ionic-angular';
export class LoginPage {
constructor(public menuCtrl: MenuController) {
}
ionViewWillEnter() {
this.menuCtrl.swipeEnable( false )
}
ionViewDidLeave() {
this.menuCtrl.swipeEnable( true )
}
}
IONIC 4: Sept2019
try this code to in your login.page.ts
Step1: import { MenuController } from '#ionic/angular';
Step2: constructor(public menuCtrl: MenuController) { }
(below constructo)
Step3: ionViewWillEnter() {
this.menuCtrl.enable(false);
}
ionViewDidLeave() {
this.menuCtrl.enable(true);
}
this code will help you to work with side menu flawlessly on any screen, if you login & re-login and try it will work now.
same issue here. just add hide-nav-bar="true" to the ion-view
<ion-view hide-nav-bar="true">
Hope it helps!
What you can do is define the login page without a sidemenu. Check your login page HTML template. Make sure you do not have the <ion-side-menus> and <ion-side-menu> elements in it. These are used on pages that need to have a sidemenu.
Your login page should look like this:
<ion-view>
<ion-content>
<!--your page content goes in here-->
</ion-content>
</ion-view>
To have sidemenu on other pages, just put the sidemenu content in a parent state which in your code is the app state.
Your menu.html file:
<ion-view>
<ion-side-menus>
<ion-side-menu>
<!--put your side menu content here-->
<!--any child state of app will inherit this sidemenu-->
</ion-side-menu>
<ion-side-menu-content>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
</ion-side-menus>
</ion-view>
A little late to the game but this is another option for those (like me) who need to keep their login view within the side-menu layout but need to hide the side menu button while keeping the view title.
Inside the login.html view use the ion-header-bar directive to create a new header with a title and then hide the ion-nav-bar in the side-menu layout via the ion-view tag.
Example (login.html)
<ion-header-bar class="bar-positive" align-title="center">
<h1 class="title">Login</h1>
</ion-header-bar>
<ion-view hide-nav-bar="true">
<!-- Login content goes here -->
</ion-view>
Then if you need to disable any drag gestures do so in the controller like #waqas suggests.
I have made a small demo for the question.
Plunker Demo
If you want a page differently from sidemenu.Create a new Parent state.
For example
$stateProvider
.state('landing', {
url: '/landing',
controller: 'landingCtrl',
templateUrl: 'landing.html'
});
Html :
<ion-view class="view-bg-blue" >
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
</ion-nav-buttons>
<ion-content padding="true">
<h3 class="text-center">Welcome To Landing Page</h3>
<div class="row">
<div class="col">
<div class="text-center">
<h4>My App</h4>
<div class="row">
<div class="col">
<input placeholder="User">
</div>
</div>
<div class="row">
<div class="col">
<input placeholder="password">
</div>
</div>
<a class="button icon-right ion-chevron-right button-calm" ng-click="open()">Login</a>
</div>
</div>
</div>
</ion-content>
</ion-view>
Then call this state using /landing when ever you want.
I know this is late but here is a quick and easy solution.
Add this in your login Controller
$scope.$on('$ionicView.afterEnter', function(event) {
$ionicSideMenuDelegate.canDragContent(false);
});
//enable side menu drag before moving to next view
$scope.$on('$ionicView.beforeLeave', function(event) {
$ionicSideMenuDelegate.canDragContent(true);
});
<ion-side-menus>
bcn
<ion-tab title="ALL" href="#/dashbord/all" class="bgorange">
<ion-nav-view name="all"></ion-nav-view>
</ion-tab>
<ion-tab title="INFO" class="bgorange" href="#/dashbord/info">
<ion-nav-view name="info"></ion-nav-view>
</ion-tab>
<ion-tab title="EVENTS" class="bgorange" href="#/dashbord/events">
<ion-nav-view name="events"></ion-nav-view>
</ion-tab>
</ion-tabs>
<ion-nav-view></ion-nav-view>
</ion-pane>
<div ng-include src="calender.html"></div>
<ion-side-menu side="left">
<ion-content has-header="true">
<ion-list>
<ion-item menu-close class="item-icon-left bottombordernone" href="#/dashbord">
<i class="icon ion-home"></i>
What's New
</ion-item>
<ion-item menu-close class="item-icon-left bottombordernone">
<i class="icon ion-chatbox-working"></i>
Feedback
</ion-item>
<ion-item menu-close class="item-icon-left bottombordernone" ng-click="logout()">
<i class="icon ion-power"></i>
Logout
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
#Zulu here's my full code.
I hope this Ex. work for you.
// index.html
<body>
<section ui-view></section>
</body>
// routes.js
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html'
})
$urlRouterProvider.otherwise('/login')
it's work, see more here: angular-ui/ui-router
You have to watch the slide menu.
If it is open, you have to toggle it and close.
.controller('kayTOlCtrl', function($scope,$ionicSideMenuDelegate) {
//
$scope.$watch(function () {
return $ionicSideMenuDelegate.getOpenRatio();
},
function (ratio) {
if (ratio != 0) {
$ionicSideMenuDelegate.toggleRight();
}
});
})
Calling $ionicSideMenuDelegate.canDragContent(false) does disable the ability to swipe to access the menu, but does not hide the hamburger toggle button in the navbar (if you have one). To do that, you can use ng-show with $root binding in your ion-side-menu-content element like this:
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"
ng-show="$root.showMenuIcon">
</button>
</ion-nav-buttons>
Then in your login controller:
$scope.$on('$ionicView.beforeEnter', function (event) {
$scope.$root.showMenuIcon = false;
$ionicSideMenuDelegate.canDragContent(false);
});
$scope.$on('$ionicView.beforeLeave', function (event) {
$scope.$root.showMenuIcon = true;
$ionicSideMenuDelegate.canDragContent(true);
});
you can also add this to your main app controller:
$scope.$root.enableLeft = true;
$scope.$root.showMenuIcon = true;
and simply switch it to false in every controller you dont want your side menu appear in:
$scope.$root.enableLeft = false;
$scope.$root.showMenuIcon = false;
add is-enabled="$root.enableLeft" to your html tag and ng-show="$root.showMenuIcon" to the button inside html tag.
Based on various answers here from everyone and 15 minutes of trying, here is my working example of it, and it should work as simply doing copy-paste
Your view, like login.html
<ion-view hide-nav-bar="true">
<ion-header-bar class="bar-light title-image" align-title="center">
<h1 class="title">Title</h1>
</ion-header-bar>
<ion-content>
</ion-content>
</ion-view>
Your related controller, like LoginCtrl
function LoginCtrl($scope, $ionicSideMenuDelegate) {
$scope.$on('$ionicView.afterEnter', function(event) {
$ionicSideMenuDelegate.canDragContent(false);
});
//enable side menu drag before moving to next view
$scope.$on('$ionicView.beforeLeave', function(event) {
$ionicSideMenuDelegate.canDragContent(true);
});
}
.state('login', {
url: '/login',
controller: 'LoginCtrl',
templateUrl: 'templates/loginpage.html'
})
.state('app.account', {
url: '/account',
views: {
'menuContent': {
templateUrl: 'templates/account.html',
controller: 'AccountCtrl'
}
}
})
import {IonicApp, Page, NavController, MenuController} from 'ionic/ionic';
import {TabsPage} from '../tabs/tabs';
import {SignupPage} from '../signup/signup';
import {UserData} from '../../providers/user-data';
#Page({
templateUrl: 'build/pages/login/login.html'
})
export class LoginPage {
constructor(nav: NavController, userData: UserData, menu: MenuController) {
this.nav = nav;
this.userData = userData;
this.login = {};
this.submitted = false;
this.menu = menu;
}
onLogin(form) {
this.submitted = true;
if (form.valid) {
this.userData.login();
this.nav.push(TabsPage);
}
}
onSignup() {
this.nav.push(SignupPage);
}
onPageDidEnter() {
// the left menu should be disabled on the login page
this.menu.enable(false);
}
onPageDidLeave() {
// enable the left menu when leaving the login page
this.menu.enable(true);
}
}
<ion-pane ion-side-menu-content drag-content="false">
<ion-header-bar class="bar-dark">
<h1 class="title">Cards</h1>
</ion-header-bar>
<ion-content scroll="true">
</ion-content>
</ion-pane>
This is works for me ...
I think the simplest solution in opening the login page in a modal view, checkout $ionicModal

Resources