Though I'm sure this is something that isn't uncommon in ionic development, I can't seem to find anything on the web that explains this. If I have the following:
<body ng-app="myApp">
<ion-nav-bar class="bar-positive">
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</body>
And one of the views that I use in the ion-nav-view looks like this for exmaple:
<ion-view view-title="Profile" ng-controller="profileController" class="profile-view">
<ion-content class="padding has-header">
....
How do I display a back button (really just the ion-chevron-left icon) for iOS only, and have it hidden on other devices that have a dedicated hardware button?
There are a couple of ways to achieve platform specific behaviour. You can read up on the back button specifically, here.
In your controller, you can use the ionic.Platform utility to determine the current platform and the Ionic NavBarDelegate to show/hide the button.
HTML:
<body ng-app="app" ng-controller="appCtrl">
<ion-nav-bar class="bar-positive">
<ion-nav-back-button></ion-nav-bar-back-button>
</ion-nav-bar>
</body>
Controller:
.controller('appCtrl', function($scope, $ionicNavBarDelegate) {
var isIOS = ionic.Platform.isIOS();
$ionicNavBarDelegate.showBackButton(isIOS);
});
In your css, define separate classes to show/hide the element depending on the platform. From here.
HTML:
<body ng-app="app" ng-controller="appCtrl">
<ion-nav-bar class="bar-positive">
<ion-nav-back-button class="platform-nav"></ion-nav-bar-back-button>
</ion-nav-bar>
</body>
CSS:
.platform-ios .platform-nav {
display: block;
}
.platform-android .platform-nav {
display: none;
}
Related
I have modal for displaying Attachments.
When I display one image in modal and pinch zoom , close the modal and click on second image, 2nd image is already zoomed.
How to stop this from happening?
<script id="modal.html" type="text/ng-template">
<ion-modal-view>
<div class="bar bar-header" class="ng-cloak">
<button class="button button-clear ion-ios-arrow-left fontSize25" ng-click="closeModal()"></button>
<h1 class="title customeHeared white-color">Attachment</h1>
</div>
<ion-content>
<ion-scroll zooming="true" direction="xy" delegate-handle="zoom-pane" class="zoom-pane" min-zoom="1">
<img ng-src="{{imagePath}}" style="width: 100%;padding: 20%;"/>
</video>
</ion-scroll>
</ion-content>
</ion-modal-view>
</script>
I have not found any solution for this, Closing this now.
If anyone comes here and finds it with an answer please let me know with a comment.
The example code for the ion-nav-view directive doesn't actually show its usage.
So I'm unsure how to use it.
Here is the link to the documentation:
http://ionicframework.com/docs/api/directive/ionNavView/
under the USAGE heading it says this:
on app start, $stateProvider will look at the url, see if it matches
the index state, and then try to load home.html into the
.
Pages are loaded by the URLs given. One simple way to create templates
in Angular is to put them directly into your HTML file and use the
syntax. So here is one way to put
home.html into our app:
<script id="home" type="text/ng-template">
<!-- The title of the ion-view will be shown on the navbar -->
<ion-view view-title="Home">
<ion-content ng-controller="HomeCtrl">
<!-- The content of the page -->
Go to music page!
</ion-content>
</ion-view>
</script>
This is good to do because the template will be cached for very fast
loading, instead of having to fetch them from the network.
Do I nest all of that inside of an ion-nav-view directive? Another reason for my confusion is because in one of the ionic templates the framework provides I've seen ion-nav-view opened and closed with nothing in between it this (code below is copy and pasted directly from one of Ionic's templates) :
<body ng-app="myApp">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<!--
The views will be rendered in the <ion-nav-view> directive below
Templates are in the /templates folder (but you could also
have templates inline in this html file if you'd like).
-->
<ion-nav-view></ion-nav-view>
</body>
This <ion-nav-view> behaves like a placeholder. Your other html files that you create under templates folder goes in there. So for example you then have "employees.html" in your templates folder. So the markup of "employees.html" will look something like this:
<ion-view view-title="Employees">
<ion-content>
<ion-list>
<ion-item ng-repeat="item in items">
Hello, {{item}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
the above is complete html that will be sitting in "employees.html". Basically this is the html that will be placed inside <ion-nav-view> tags.
Hope this helps.
There are similar question but not this exact one. I have this structure in an ionic app view
<ion-view>
<ion-nav-title>
<a id="go_to_app" href="#startseite">
<span class="ion-android-exit"></span>
</a>
<img src="img/logo_header.png">
</ion-nav-title>
<ion-content class="star-wrap">
.
. contents
.
</ion-content class="star-wrap">
What I'm trying to achieve is show the ion-android-exit button instead of the menu button in this specific view.
Is this possible?
There was a (way) easy and simple way to do this.
Adding <ion-nav-buttons></ion-nav-buttons> inside <ion-view></ion-view> will rewrite the menu button with whatever I want, or just hide it with no contents.
You need to use ng-if like in example here.
http://codepen.io/anon/pen/AXkJGa
after setting the value of ng conditional to true in the controller.
Example HTML
<title>Ionic Modal</title>
<body ng-controller="State1Ctrl">
<ion-nav-bar>
<ion-nav-view>
<ion-view>
<ion-nav-title>
<a id="go_to_app" href="#startseite">
<span class="ion-android-exit" ng-if="!hidethisview"></span>
</a>
</ion-nav-title>
<ion-content>
Some super content here!
</ion-content>
</ion-view>
</ion-nav-view>
</ion-nav-bar>
And JS
angular.module('ionicApp', ['ionic'])
.controller('State1Ctrl', function($scope, $state) {
if($state.current.name=="")// you need to have your state name inside quotes
//this example don't have one
{
$scope.hidethisview=true;
}
});
Not sure if it's ionic thats buggy or something else ..
I am creating a simple header (and nothing else)
<ion-header-bar class="bar-positive">
<h1 class="title">Title!</h1>
<div class="buttons">
<button class="button">Right Button</button>
</div>
</ion-header-bar>
I expect to see a "Title" and a button on the header bar. But that doesn't happen.
http://plnkr.co/edit/vPkirnzlFX1I9B7W9H8N?p=preview
problem was with the ionic bundle:
using the below solved the issue:
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
I've got this strange behaviour.
In my index.html I declared:
<body>
<ion-nav-view></ion-nav-view>
</body>
Then in my page.html I used the followin markup:
<ion-view title="Purchases" hide-back-button="true">
<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-content> ... </ion-content>
</ion-view>
The view correctly set a button to toggle side menu, but also, automatically, create a header:
<ion-nav-bar class="bar-stable nav-title-slide-ios7 bar bar-header nav-bar disable-user-behavior">
How can I change its styles? For instance: I would like to set it as a "bar-energized".
I also tried to insert, in index.html above , the following markup (amany examples show), but it does not seem to work (nav bar header remains grey):
<ion-nav-bar class="bar-energized nav-title-slide-ios7"></ion-nav-bar>
The only way it seems working is by declaring and buttons inside each and every
Just realized it was really a newbie question! I was starting from a Ionic sidemenu template, and the misterious "bar-stable" was declared inside "ion-pane ion-side-menu-content" in my menu.html file.
Hope it may helps someone other!