Hide ion items in side menu after login in Ionic/AngularJs - angularjs

i'm new in Angular and Ionic. I'm trying to hide some ion items from the side menu based on the login status but it doesn't work. Do you know why?
This is the app.js file - it's basicly the default app.js file from the ionic side menu template.
angular.module('starter', ['ionic', 'starter.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
$ionicConfigProvider.tabs.position('top');
$stateProvider.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
});
$stateProvider.state('app.dashboard', {
url: '/dashboard',
views: {
'menuContent': {
templateUrl: 'templates/dashboard.html',
controller: 'AppCtrl'
}
}
});
$stateProvider.state('app.login', {
url: '/login',
views: {
'menuContent': {
templateUrl: './templates/login.html',
controller: 'AppCtrl'
}
}
});
$stateProvider.state('app.single', {
url: '/playlists/:playlistId',
views: {
'menuContent': {
templateUrl: 'templates/playlist.html',
controller: 'PlaylistCtrl'
}
}
});
$urlRouterProvider.otherwise('/app/login');
});
This is the controllers file - After the login form is submitted and
it passes the validation it will call loginSuccess() function which
will set the "isLogged" variable to true. Now the side menu elements
which have ng-show attributes should appear but they don't. If i
insert a console.log in the loginSuccess function it will show that
the variable has the value true but still it doesn't work.
(function() {
'use strict';
var app = angular.module('starter.controllers', []);
app.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $state) {
$scope.bothErrors = false;
$scope.emailError = false;
$scope.isLogged = false;
$scope.loginData = {};
$scope.doLogin = function () {
if($scope.validateEmail($scope.loginData.username)) {
if($scope.loginData.username == 'george#wgeorge.ro' && $scope.loginData.password == '1234') {
$scope.loginSuccess();
}else{
$scope.bothErrors = true;
$scope.emailError = false;
}
}else{
$scope.emailError = true;
}
};
$scope.loginSuccess = function () {
$state.go('app.dashboard');
$scope.bothErrors = false;
$scope.isLogged = !$scope.isLogged;
};
$scope.logOut = function(){
$scope.isLogged = !$scope.isLogged;
$state.go('app.login');
};
$scope.validateEmail = function (email) {
var re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
});
}());
This is the sidemenu html file
<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-title>
<img src="img/logo.png" class="logo">
</ion-nav-title>
<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-content>
<ion-list>
<ion-item menu-close href="#/app/dashboard">
Acasa
</ion-item>
<ion-item ng-show="showProfile" menu-close href="#/app/playlists">
item1
</ion-item>
<ion-item menu-close href="#/app/playlists">
item2
</ion-item>
<ion-item menu-close href="#/app/playlists">
item3
</ion-item>
<ion-item ng-show="isLogged" menu-close href="#/app/playlists">
item4
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>

Related

ionic : Enable menu with back views issues

I created the application using with ionic slide menu and navigation between multiple views.
For example, I have View-A View-B and View-C.
If I used to navigate View-A to View-B and come back home screen the toggle left slide menu button is enabled.
If I used to navigate View-A to View-B then View-C and come back home screen the toggle left slide menu button got disabled.
Let me explain my code below:
tabs.html
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-back-button> Back
</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>
<!-- Logout -->
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-ios-person-outline" on-tap="doLogout()"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
<!-- Activity Tab -->
<ion-tab title="Activity" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/userActivity">
<ion-nav-view name="tab-userActivity"></ion-nav-view>
</ion-tab>
<!-- Scheduled Tasks Tab -->
<ion-tab title="Call Lists" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/overallCallsCtrl">
<ion-nav-view name="tab-overallCallsCtrl"></ion-nav-view>
</ion-tab>
<!-- Dashboard -->
<ion-tab title="Dashboard" icon-off="ion-ios-people-outline" icon-on="ion-ios-people" href="#/tab/dashboard">
<ion-nav-view name="tab-dashboard"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-side-menu-content>
<!-- Side Menu (left) -->
<ion-side-menu side="left">
<ion-header-bar class="bar-positive">
<h1 class="title">Menu</h1>
</ion-header-bar>
<ion-content class="customSlide">
<ion-list>
<ion-item class="item item-avatar">
<img src="img/men.png"><br>Welcome John!
</ion-item>
<ion-item menu-close href="#/tab/userActivity">
<i class="ion-ios-list-outline"></i>
Activity
</ion-item>
<ion-item menu-close href="#/tab/installationCall">
<i class="ion-ios-cloud-download-outline"></i>
Installation
</ion-item>
<ion-item menu-close href="#/tab/correctiveMaintenanceCall">
<i class="ion-ios-settings"></i>
Corrective Maintenance
</ion-item>
<ion-item menu-close href="#/tab/preventiveMaintenanceCall">
<i class="ion-ios-settings"></i>
Preventive Maintenance
</ion-item>
<ion-item menu-close href="#/tab/calibrationCall">
<i class="ion-ios-pulse"></i>
Calibration
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
app.js
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('revolApp', ['ionic', 'revolApp.UserSignInController','revolApp.DashboardController','revolApp.ActivityController','revolApp.CalibrationController','revolApp.CorrectiveMaintenanceController','revolApp.PreventiveMaintenanceController', 'revolApp.InstallationController','revolApp.ScheduledCallsController','revolApp.AddCallController','revolApp.AssignCallController','revolApp.CloseCallController','revolApp.ResponseCallController','revolApp.ScheduleCallController','revolApp.FeedbackController','revolApp.TabController','revolApp.OverallCallsController'])
.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 && 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, $ionicConfigProvider) {
/*
// note that you can also chain configs
$ionicConfigProvider.backButton.text('Back');
*/
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
// State to represent Login View
.state('userSignIn', {
url: '/userSignIn',
cache: false,
templateUrl: 'View/SigninView.html',
controller: 'UserSignInCtrl',
})
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
cache: false,
abstract: true,
templateUrl: 'View/tabs.html',
controller: 'TabCtrl'
})
.state('tab.userActivity', {
url: '/userActivity',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/ActivityView.html',
controller: 'ActivityCtrl'
}
}
})
.state('tab.scheduledInsideTabCalls', {
url: '/scheduledInsideTabCalls',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/ScheduledCallsView.html',
controller: 'ScheduledCallsCtrl'
}
}
})
.state('tab.addCall', {
url: '/addCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/AddCallView.html',
controller: 'AddCallCtrl'
}
}
})
.state('tab.assignCall', {
url: '/assignCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/AssignCallView.html',
controller: 'AssignCallCtrl'
}
}
})
.state('tab.scheduleCall', {
url: '/scheduleCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/ScheduleCallView.html',
controller: 'ScheduleCallCtrl'
}
}
})
.state('tab.responseCall', {
url: '/responseCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/ResponseCallView.html',
controller: 'ResponseCallCtrl'
}
}
})
.state('tab.closeCall', {
url: '/closeCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/CloseCallView.html',
controller: 'CloseCallCtrl'
}
}
})
.state('tab.feedbackCall', {
url: '/feedbackCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/FeedbackView.html',
controller: 'FeedbackCtrl'
}
}
})
.state('tab.installationCall', {
url: '/installationCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/InstallationView.html',
controller: 'InstallationCtrl'
}
}
})
.state('tab.correctiveMaintenanceCall', {
url: '/correctiveMaintenanceCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/CorrectiveMaintenanceView.html',
controller: 'CorrectiveMaintenanceCtrl'
}
}
})
.state('tab.preventiveMaintenanceCall', {
url: '/preventiveMaintenanceCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/PreventiveMaintenanceView.html',
controller: 'PreventiveMaintenanceCtrl'
}
}
})
.state('tab.calibrationCall', {
url: '/calibrationCall',
cache: false,
views: {
'tab-userActivity': {
templateUrl: 'View/CalibrationView.html',
controller: 'CalibrationCtrl'
}
}
})
.state('tab.overallCallsCtrl', {
url: '/overallCallsCtrl',
cache: false,
views: {
'tab-overallCallsCtrl': {
templateUrl: 'View/OverallCallsView.html',
controller: 'OverallCallsCtrl'
}
}
})
.state('tab.dashboard', {
url: '/dashboard',
cache: false,
views: {
'tab-dashboard': {
templateUrl: 'View/DashboardView.html',
controller: 'DashboardCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/userSignIn');
});
Then If I navigate ViewA from C like below the slide menu toggle button got disabled.
Controller handling :
ActivityController.js // in this page toggle visible in simulator
$state.go('tab.scheduledInsideTabCalls');
In ActivityController Html and Signin Html page alone I set hide-back-button="true" other than that all HTML page I set hide-back-button="false"
AssignCallController.js // in this page back button visible in simulator
$state.go('tab.userActivity');
After reached userActivity page toggle got disabled.
It seems like you are using this code in an ion-nav-view. you should put this view as the base. Then extend them with a <ion-nav-view></ion-nav-view> in this code. example
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-navicon" menu-toggle="right">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
<!-- Store Tab -->
<ion-tab title="Winkels" icon-off="ion-home" icon-on="ion-home" ui-sref="menu.shop">
<ion-nav-view name="tab-shop"></ion-nav-view>
</ion-tab>
<!-- Cart Tab -->
<ion-tab title="Winkelwagen" icon-off="ion-bag" icon-on="ion-bag" ui-sref="menu.cart">
<ion-nav-view name="tab-cart"></ion-nav-view>
</ion-tab>
<!-- Contact Tab -->
<ion-tab title="Contact" icon-off="ion-email" icon-on="ion-email" ui-sref="menu.contact">
<ion-nav-view name="tab-contact"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-side-menu-content>
<ion-side-menu side="right">
<ion-header-bar class="bar-stable">
<h1 class="title">Menu</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>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
routes:
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova'])
.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 && 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) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
// setup an abstract state for the tabs directive
.state('menu', {
url: '/menu',
abstract: true,
templateUrl: 'templates/menu.html'
})
// Each tab has its own nav history stack:
.state('menu.shop', {
cache: false,
url: '/shop',
views: {
'tab-shop': {
templateUrl: 'templates/tab-shop.html',
controller: 'ShopCtrl'
}
}
})
.state('menu.cart', {
cache: false,
url: '/cart',
views: {
'tab-cart': {
templateUrl: 'templates/tab-cart.html',
controller: 'CartCtrl'
}
}
})
.state('menu.contact', {
url: '/contact',
views: {
'tab-contact': {
templateUrl: 'templates/tab-contact.html',
controller: 'ContactCtrl'
}
}
})
.state('menu.store', {
cache: false,
url: '/store/{storeId}',
views: {
'tab-shop': {
templateUrl: 'templates/storeView.html',
controller: 'StoreViewCtrl',
}
}
})
.state('menu.category', {
cache: false,
url: '/category/{categoryId}',
views: {
'tab-shop': {
templateUrl: 'templates/categoryView.html',
controller: 'CategoryViewCtrl',
}
}
})
.state('menu.product', {
cache: false,
url: '/product/{productId}',
views: {
'tab-shop': {
templateUrl: 'templates/productView.html',
controller: 'ProductViewCtrl',
}
}
}).state('menu.checkout', {
cache: false,
url: '/checkout}',
views: {
'tab-cart': {
templateUrl: 'templates/checkoutView.html',
controller: 'CheckoutCtrl',
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/menu/shop');
});
Look at the abstract state of the menu route. This makes sure the rest of the views are loaded within this base view.
Button Hidden On Child Views
By default, the menu toggle button will only appear on a root level side-menu page. Navigating in to child views will hide the menu- toggle button. They can be made visible on child pages by setting the enable-menu-with-back-views attribute of the ionSideMenus directive to true.
try changing "&lt ion-side-menus enable-menu-with-back-views="false" &gt" to "&lt ion-side-menus enable-menu-with-back-views="true" &gt"

The Google Map doesn't appear working with Ionic and AngularJS

The Google Map doesn't appear. I work with Ionic and AngularJS and I use the Geolocation plugin.
This is my routing for the app:
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
.state('menu.rServation', {
url: '/Réservation',
views: {
'side-menu21': {
templateUrl: 'templates/rServation.html',
controller: 'rServationCtrl'
}
}
})
.state('menu.voiture', {
url: '/Voiture',
views: {
'side-menu21': {
templateUrl: 'templates/voiture.html',
controller: 'voitureCtrl'
}
}
})
.state('menu.paramTres', {
url: '/Paramètres',
views: {
'side-menu21': {
templateUrl: 'templates/paramTres.html',
controller: 'paramTresCtrl'
}
}
})
.state('menu.LocationMap', {
url: '/Location',
views: {
'side-menu21': {
templateUrl: 'templates/Locationmap.html',
controller: 'LocationMapCtrl'
}
}
})
.state('menu.LocationMMap', {
url: '/Locationn',
views: {
'side-menu21': {
templateUrl: 'templates/LocationMMap.html',
controller: 'MapCtrl'
}
}
})
.state('menu.login', {
url: '/Login',
views: {
'side-menu21': {
templateUrl: 'templates/login.html',
controller: 'loginCtrl'
}
}
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'templates/menu.html',
abstract:true
})
.state('menu.detailsVoiture', {
url: '/Voiture/:Id',
views: {
'side-menu21': {
templateUrl: 'templates/detailsVoiture.html',
controller: 'voitureCtrl'
}
}
})
.state('menu.conexion', {
url: '/Conexion',
views: {
'side-menu21': {
templateUrl: 'templates/conexion.html',
controller: 'conexionCtrl'
}
}
})
.state('menu.detailsPreReservation',{
url: '/DetailsPreReservation',
views: {
'side-menu21': {
templateUrl: 'templates/detailsPreReservation.html',
controller: 'detailsPreReservationCtrl'
}
}
})
.state('menu.profile',{
url: '/profile',
views: {
'side-menu21': {
templateUrl: 'templates/profil.html',
controller: 'profilCtrl'
}
}
})
$urlRouterProvider.otherwise('/side-menu21/Réservation')
});
and this is mu controller
.controller('MapCtrl', function($scope, $state, $cordovaGeolocation) {
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
}, function(error){
console.log("Could not get location");
});
})
and this my view:
<ion-view>
<ion-content>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
</ion-view>
and this my menu.html for side menu:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<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="side-menu21"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-calm">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header">
<ion-list>
<ion-item ui-sref="menu.rServation" menu-close="" >
<i class="icon ion-home balanced ">Réservation</i>
</ion-item>
<ion-item ui-sref="menu.voiture" menu-close="" >
<i class="icon ion-model-s balanced">Voitures</i>
</ion-item>
<ion-item ui-sref="menu.paramTres" menu-close="" >
<i class="icon ion-android-settings balanced">Paramètres</i>
</ion-item>
<ion-item ui-sref="menu.LocationMap" menu-close="" >
<i class="icon ion-map balanced">Location Agence</i>
</ion-item>
<ion-item ui-sref="menu.LocationMMap" menu-close="" >
<i class="icon ion-map balanced">Locationn Agence</i>
</ion-item>
<ion-item ui-sref="menu.login" menu-close="" >
<i class="icon ion-log-in balanced">Login</i>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
This is an image for the template and no error
You didn't set the height for the container:
<style>
#map {
height: 400px;
}
</style>

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">

How to ng-hide login button after successful login Ionic?

I have started sideMenu app in ionic and tried some implementation. Initially, ionicModal is used to show login so i change it with ion-list item like;
<ion-side-menu side="left" >
<ion-header-bar class="bar-stable bar-dark">
<a ng-click="redirectToWeb()" > <h1 class="title">NerdApp</h1></a>
</ion-header-bar>
<ion-content >
<ion-list class="BGcolorDG">
<ion-item nav-clear menu-close class="BGcolorDG item item-icon-left item-content-modified" href="#/app/login" ng-show="control.showLogin" > <!--ng-click="login()" -->
<i class="icon ion-locked"></i> <span>Login</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/search" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-search"></i><span>Search</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/browse" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-ios-browsers"></i><span>Browse</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/playlists" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-music-note"></i> <span>Playlists</span>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
and provide routeState as
state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.login', {
url: "/login",
views: {
'menuContent': {
templateUrl: "templates/login.html",
controller: "LoginCtrl"
}
}
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller: "HomeCtrl"
}
}
})
And default route to home controller.
$urlRouterProvider.otherwise('/app/home');
the app controller is as
.controller('AppCtrl', function($scope,$timeout,$location,$rootScope) {
$scope.control = {
showLogin:true
};
if($rootScope.showLogin != undefined && $rootScope.showLogin == false){
$scope.control.showLogin = false;
}
})
Inside loginControl i am checking and redirecting it back to home controller as
$scope.login = function() {
if ($scope.loginData.username == 'hassaan' && $scope.loginData.password == 'khan') {
$rootScope.showLogin = false;
// $location.path('#/app');
$state.go('app.home');
}else{
alert('Incorrect credentials');
}
}
i have tried both $location.path and $state.go and what its doing is redirecting to home page but 'not showing the sidemenu' and when i inspect in browser it showing sidemenu hidden.
The flow images of test app is as
Try use $rootScope
pass it to AppCtrl
.controller('AppCtrl', function (...., $rootScope) {
// and then
$rootScope.control = {
showProfile: false
};
after success authentication - make it true
$rootScope.control = {
showProfile: true
};
now it should work as you expected
Don't use $rootscop if you dont need to.
You can send variables to other controllers with the router from angular using params.
.state('menu.employeeInfo', {
url: '/employeeInfo',
views: {
'side-menu21': {
templateUrl: 'templates/employeeInfo.html',
controller: 'employeeInfoCtrl'
}
},
params: {
appointmentObj: null,
subassignmentObj: null
}
})
You can then pass these vars in the following manner.
$scope.gotoAppointment = function (Appointment, Subassignment) {
$state.go('menu.employeeInfo', { appointmentObj: Appointment, subassignmentObj: Subassignment }, { reload: true });
}

Back Navigation Button not showing

I'm new to Ionic / Angularjs and learning to use it.
I'm fetching menu links from server and on clicking, it goes to detail page but Back button not showing. It is working in Tab Menu example from ionic.
Also when i click browser Back Button, it shows on Homepage (I don't think it should show?)
Could anyone tell me what's wrong?
Codes are as below:
Controller.js
angular.module('GAC.controllers', [])
.controller('AppCtrl', function($scope, pagesService) {
//GET PAGE LIST
pagesService.fetchFromServer().then( function(list){
$scope.pageList = list;
});
})
.controller('PageCtrl', function($scope, $stateParams, pagesService) {
if(!isNaN(parseInt($stateParams.pageId))){
pagesService.fetchById( $stateParams.pageId ).then(function(page){
$scope.page = page;
});
}else{
alert('No Such Page'); // How to redirect to Homepage
}
})
.factory('pagesService', ['$http', function( $http ){
var service = {};
service.fetchFromServer = function( ){
var promise = $http.jsonp('http://m.aboudcar.com/server/pages/?callback=JSON_CALLBACK')
.then( function(response ){
return response.data;
})
return promise;
};
service.fetchById = function( pageId ){
var promise = $http.jsonp('http://m.aboudcar.com/server/pages/fetchbyid/'+pageId+'?callback=JSON_CALLBACK')
.then( function(response ){
return response.data;
})
return promise;
};
return service;
}])
App.js
angular.module('GAC', ['ionic', 'GAC.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.cars', {
url: "/cars",
views: {
'menuContent' :{
templateUrl: "templates/cars.html",
controller: 'CarsCtrl'
}
}
})
.state('app.single', {
url: "/pages/:pageId",
views: {
'menuContent' :{
templateUrl: "templates/page.html",
controller: 'PageCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/cars');
});
Menu.html
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-stable nav-title-slide-ios7">
<ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<header class="bar bar-header bar-stable">
<h1 class="title">Menu</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item nav-clear menu-close ng-repeat="page in pageList" href="{{page.url}}">
{{page.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
Page.html
<ion-view title="{{page.name}}">
<ion-content class="has-header">
<h1>{{page.name}}</h1>
{{page.content}}
</ion-content>
</ion-view>

Resources