Ionic Framework Page Transition - angularjs

Does anyone successfully add a page transition on nested views in angularjs/ionicframework
This is my code for my nested views. When I go to this page transition is not working
<ion-side-menus>
<ion-nav-view name="left"></ion-nav-view>
<ion-nav-view name="main"></ion-nav-view>
</ion-side-menus>
But if I put only this code
<ion-nav-view name="main"></ion-nav-view>
Page transition is working
I hope you can help me with this one. Thank you!

In you index.html you should have a single ion-nav-view (you can populate this ion nav view with multiple ion views) like so:
<div ng-app="ffApp" animation="slide-left-right" ng-controller="authRoute.controller">
<ion-nav-view></ion-nav-view>
Then you want to create states/child states to fill the view:
$stateProvider
.state('authenticate', {
url: '/authenticate',
templateUrl: 'templates/authentication.html'
})
.state('loginIos', {
url: '/loginIos',
templateUrl: 'templates/loginIos.html',
controller: 'loginIos.controller',
})
.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller: 'home.controller',
}).state('home.home1', {
url: "/home",
views: {
'menuContent' :{
templateUrl: "home.html"
}
}
})
Inside the template file you will have a ion-view with a side menu, if you want to populate the side menu as a child state you can create a child state inside the state provider and then place a ion-nav-view in side menu.
<ion-view>
<ion-side-menus>
<!-- Center content -->
<ion-side-menu-content ng-controller="ContentController">
<!-- Left menu -->
<ion-side-menu side="left">
</ion-side-menu>
<!-- Right menu -->
<ion-side-menu side="right">
</ion-side-menu>
<ion-side-menu-content>
<!-- Main content, usually <ion-nav-view> -->
</ion-side-menu-content>
</ion-side-menus>
</ion-view>
then when you navigate to a child state such as home.home1 the template for home.home1 will fill the menucontent ion-nav-view which is included in the home state template.
See this example: http://codepen.io/mhartington/pen/Bicmo/

Related

Angularjs template view is not being cached, it refreshes every time

Scratching my head on this one, I have a tab that has two views in it, the default view and a secondary view. The user must click a button (in the default view) to get to the secondary view...and once in the secondary view must click a button to go back to the default view.
I have cache: true, on both views and caching is working (as intended) on the default view, but is not working on the secondary view. Every time the user goes to the secondary view it refreshes the content with a call to the server. Regardless of which view the user is on, if the user goes to another tab and comes back again, neither default or secondary views get refreshed (as intended), its only when switching from the default view to the secondary view does it happen.
There is nothing else in the controllers for either views that is messing with or dealing with cache. How can I resolve this or what can I look for that might be causing this?
In app.js:
.state('tab.current', { // primary/default view
cache: true,
url: '/current',
params: tabParams,
views: {
'tab-current': {
templateUrl: 'templates/tab-current.html',
controller: 'CurrentCtrl'
}
}
})
.state('tab.current-detail', {
cache: true,
url: '/current/:ceID',
params: tabParams,
views: {
'tab-current': {
templateUrl: 'templates/detail-current.html',
controller: 'CurrentDetailCtrl'
}
}
})
.state('tab.past', { // secondary view
cache: true,
url: '/past',
params: tabParams,
views: {
'tab-current': {
templateUrl: 'templates/tab-past.html',
controller: 'PastCtrl'
}
}
})
.state('tab.past-detail', {
cache: true,
url: '/past/:ceID',
params: tabParams,
views: {
'tab-current': {
templateUrl: 'templates/detail-past.html',
controller: 'PastDetailCtrl'
}
}
})
I am using Ionic tabs:
<ion-tabs id="allTabs" delegate-handle="mainTabs" class="tabs-icon-bottom tabs-bottom tabs-color-active-positive" style="">
<div id="allTabsBar" style="height:100%;">
<!-- Home Tab -->
<ion-tab id="homeTab" class="icon barIconHeight" icon-off="ion-home" icon-on="ion-home" href="#/tab/home" >
<ion-nav-view id="tab-home" name="tab-home"></ion-nav-view>
</ion-tab>
<!-- Club Tab -->
<ion-tab id="clubTab" class="icon barIconHeight" icon-off="ion-people" icon-on="ion-people" href="#/tab/clubs" >
<ion-nav-view id="tab-clubs" name="tab-clubs"></ion-nav-view>
</ion-tab>
<!-- Search Tab -->
<ion-tab id="searchTab" class="icon barIconHeight" icon-off="ion-search" icon-on="ion-search" href="#/tab/search" >
<ion-nav-view id="tab-search" name="tab-search"></ion-nav-view>
</ion-tab>
<!-- Settings Tab -->
<ion-tab id="menuTab" class="icon barIconHeight" icon-off="ion-ios-settings-strong" icon-on="ion-ios-settings-strong" href="#/tab/menu" >
<ion-nav-view id="tab-menu" name="tab-menu"></ion-nav-view> <!-- class="icon ion-ios-settings-strong" -->
</ion-tab>
</div>
</ion-tabs
I believe your issue is likely your usage of href. AngularJS probably isn't getting a chance to pass off your hash routing to the location service. Since the template cache is not backed by any persistence layer (local/session storage), a full page reload will clear any cached templates.
See ngHref

Ionic side menu items back navigation

I am trying to accomplish both tabs and sliding side menu, but can't get back button appear after entering side menu item. I am new to Ionic/Angular Routing,but I am supposing that to make it work I need to manipulate with app.js and states.
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-stable bar-positive">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon" ng-click="toggleRight()"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<header class="bar bar-header bar-balanced">
<h1 class="title">MyApp</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item menu-close ui-sref="about">
About
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
And my apps.js looks like this:
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
(...tab states...)
.state('about', {
url: '/about',
templateUrl: 'templates/side/about.html',
controller: 'AboutController',
})
What should I do make back nav-button(or at least make some custom button on navigation bar to redirect home) appear when I am entering one of the side menu items and then template?
have you tried this?
$ionicNavBarDelegate.showBackButton(true);
$ionicNavBarDelegate api guide
You can include below code to enable back button.
< ion-side-menus enable-menu-with-back-views="true">
....
< /ion-side-menus>
http://ionicframework.com/docs/api/directive/ionSideMenus/

Navigation with tabs not working

I am trying to do navigation to tab list after selecting some items from the list.
when I am trying to run my code I am getting Cannot GET /tab/1337
my selection from the list looks like:
<div class="list">
<a ng-repeat="item in items"
href="/tab/{{item.queId}}"
class="item item-thumbnail-left">
My app.js looks like
.state('tabs.details', {
url: "/details/:itemqueId",
views: {
'details-tab': {
templateUrl: "templates/details.html",
controller: 'FriendDetailCtrl'
}
}
})
.state('tabs', {
url: "/tab/:itemqueId",
abstract: true,
templateUrl: "templates/tabs.html"
});
my tabs.html looks like:
<ion-view>
<ion-tabs class="tabs-icon-top">
<!-- Pets Tab -->
<ion-tab title="Dashboard" icon="icon ion-home" href="#/tab/dash">
<ion-nav-view name="tab-dash"></ion-nav-view>
</ion-tab>
<!-- Adopt Tab -->
<ion-tab title="details" icon="icon ion-heart" href="#/tab/details">
<ion-nav-view name="tab-details"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-view>
don't know what can be the issue, but hope you will help!
Thanks!
Remove the line saying abstract: true in the tabs state definition - abstract states can not get activated. See ui-router docs.
Update:
What do you actually expect to happen when hitting /tab/1337?
Available Tabs
First of all, taking a look at the current state config, you have only a single valid route, since the tab state is abstract:
/tab/:itemqueId/details/:itemqueId
See how tab.details it will append it's url the one of tab, since it's a nested state of tabs. Therefor /tab/1337 is not a valid route.
What you might be looking for is /tab/:itemqueId/details - therefor change your url for tab.details to url: "/details"
Linking
Instead of using the href attribute, you should always prefer using the ng-href directive when interpolating variables from the angular scope.
In this case I'd even suggest to use ui-sref directive from ui-router. This way you can create urls with state definition and also check if your definition is valid.
<a ui-sref="tab.details({ itemqueId: item.queId })">
In the tabs.html your links should look like this to point to an sibling state - given that tabs.dash is a valid state similar to tabs.details:
<!-- Pets Tab -->
<ion-tab title="Dashboard" icon="icon ion-home" ui-sref="^.dash">
<ion-nav-view name="tab-dash"></ion-nav-view>
</ion-tab>
<!-- Adopt Tab -->
<ion-tab title="details" icon="icon ion-heart" href="^.details">
<ion-nav-view name="tab-details"></ion-nav-view>
</ion-tab>

ionic / angular 1.3 - Missing ion-nav-back-button when ion-side-menus exist inside view

I can't seem to figure out how to get a back button to appear on a view that contains a ion-side-menus directive.
Here's the absolute simplest example I've come up with:
http://codepen.io/jsplaine/pen/YPxvXL?editors=101.
Note that the ion-views in state x.emptyView and state x.emptySideMenu are children of state x's ion-nav-view.
Here's a more in-depth example, where there exists a side-menu that is actually populated:
http://codepen.io/jsplaine/pen/ZYJRYW?editors=101
Here's the basic router, for the first codepen:
angular.module('ionicApp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('app', {
url: "/",
templateUrl: "templates/home.html",
controller: 'AppCtrl'
})
.state('x', {
url: "/x",
abstract: true,
template: '<ion-nav-view animation="slide-left-right"/>'
})
.state('x.emptyView', {
url: "/empty-view",
templateUrl: "templates/empty_view_only.html"
})
.state('x.emptySideMenu', {
url: "/empty-side-menu",
templateUrl: "templates/empty_side_menu.html"
})
})
There's a second issue with the more in-depth codepen. Depending on which tab you click first, the 2nd or the 3rd, the corresponding template gets cached for future navigation to BOTH the 2nd and 3rd template. Click the 2nd one first, then the 3rd. Then start over and click the 3rd one first then the 2nd. The fact that this is happening makes me thinking that I'm using ui-router wrong somehow.
I also don't understand why I have to define ion-nav-view in both index.html AND in the abstract state ('x') template. Isn't state 'x' a child of index.html (the empty state)?
Can someone figure out how to modify both codepens so that the back button appears on views containing a ion-side-menus directive, and for the 2nd codepen .. the 2nd and 3rd tab caching issue is resolved?
The solution can be seen here:
http://codepen.io/jsplaine/pen/wBqNmw?editors=101
It seems that ion-side-menus' parent ion-view needs a child ion-nav-bar, and enable-menu-with-back-views must be set to true.
<!-- Side Menu Nav and Burger Defined -->
<script id="templates/side_menu_with_nav.html" type="text/ng-template">
<ion-view view-title="Side Menu with Nav and Burger">
<ion-nav-bar></ion-nav-bar> <!-- HERE -->
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar>
<ion-nav-back-button class="button-icon ion-arrow-left-c"></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>
....
As the ionic directive/menuToggle docs state: https://github.com/driftyco/ionic/blob/master/js/angular/directive/menuToggle.js#L1
### 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 {#link >ionic.directive:ionSideMenus}
directive to true.
I wonder if the authors didn't take your case into account. Their model is a slide-in menu that only slides in partially and can be toggled with a menu icon. So you may be a bit off paradigm but this seemed to work for me albeit a bit lame for duplicating the nav-bar code in the template.
<script id="templates/empty_side_menu.html" type="text/ng-template">
<ion-view view-title="Empty side menu">
<ion-nav-bar align-title="center" class="nav-title-slide-ios7 bar-stable">
<ion-nav-back-button class="button-icon ion-arrow-left-c">
</ion-nav-back-button>
</ion-nav-bar>
<ion-side-menus>
</ion-side-menus>
</ion-view>
</script>

Angularjs + Ionic Framework: How to create a new route that shows the ion-tabs navigation but without defining a tab for itself?

Long title but here is a better explanation.
I have a template html file called "Login". I define a route in app.js like so
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'createAccountCtrl'
})
By using ui-sref="login" I can link to this template from anywhere which is perfect for my needs.
However the main app uses an abstract route "tab" to load the tabs template which contains the main navigation.
.state('tab.about', {
url: '/about',
views: {
'about-tab': {
templateUrl: 'templates/about.html',
controller: 'aboutCtrl'
}
}
})
<ion-tabs tabs-style="tabs-icon-top" tabs-type="tabs-default">
<!-- Home Tab -->
<ion-tab title="Home" icon="icon ion-home" href="#/tab/home">
<ion-nav-view name="home-tab"></ion-nav-view>
</ion-tab>
<!-- Products Tab -->
<ion-tab title="Earn Points" icon="icon ion-ios7-plus-outline" href="#/tab/retail-store">
<ion-nav-view name="retail-store-tab"></ion-nav-view>
</ion-tab>
</ion-tabs>
My problem is this. I want the Login page to have the main app's navigation like every other page has. That way a user who makes it to the login page, if they don't to login can still navigate off to the home or about page. But, I do not want a navigation tab/icon of its own to show.
Is is possible to just add the tabs html directly to the login.html template file or possibly hide the login icon/tab. I am open to suggestions and help. Thank you!
The tabs are meant to have their own tab icon. So you can't put the login page inside the tabs abstract view without creating a tab icon for it.
Instead of putting the login page under the tab abstract view, you should just put a separate tabbed navigation for the login page.
Load the following view into your index page.
<ion-view title="'Login'">
<ion-content has-header="true" has-footer="true" padding="true">
Login page content goes here
</ion-content>
<div class="tabs tabs-icon-left">
<a class="tab-item" href="#/tab/home">
Home
</a>
<a class="tab-item" href="#/tab/about">
About
</a>
</div>
</ion-view>

Resources