Align navbar back button on right side - css

I'm developing an ionic app and I need to align the navbar back button on right side. The following is my code:
<ion-view title="Home" ng-controller="HomeCtrl" style="padding-top: 50px">
<ion-nav-bar class="bar-balanced bar-dark">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-content scroll="true">
<ion-list>
<ion-item ng-repeat="item in items" href="#/res/{{item}}">
{{item.toUpperCase()}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
And I've tried following code for aligning button using ion-nav-buttons:
<ion-view title="Home" ng-controller="HomeCtrl" style="padding-top: 50px">
<ion-nav-bar class="bar-balanced bar-dark">
<ion-nav-buttons side="right">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content scroll="true">
<ion-list>
<ion-item ng-repeat="item in items" href="#/res/{{item}}">
{{item.toUpperCase()}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
But the above code throwing error like:
Error: [$compile:ctreq] Controller 'ionNavBar', required by directive 'ionNavBackButton', can't be found!
http://errors.angularjs.org/1.4.3/$compile/ctreq?p0=ionNavBar&p1=ionNavBackButton
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
at getControllers (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21319:19)
at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21445:33)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20853:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21457:24)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20853:13)
at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
at publicLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20728:30) <ion-nav-bar class="bar-balanced bar-dark nav-bar-container" nav-bar-transition="ios">(anonymous function) # ionic.bundle.js:25642
ionic.bundle.js:1173 'webkitMovementX' is deprecated. Please use 'movementX' instead.

You can use this code:
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-arrow-left-c" ng-click="goBack()">back
</button>
</ion-nav-buttons>
and in your controller(s):
$scope.goBack = function() {
$ionicHistory.goBack(-1);
}
P.S.: in this case no <ion-nav-back-button></ion-nav-back-button> is used
Here is an example: http://codepen.io/beaver71/pen/NNWZBp

Related

Padding top not working in ionic 3

The below is the html code for an ionic page. I am trying to apply padding and adjust the location of the content. In some places it is not working.
I want the login form to be located further down in the screen. Changing the values of <div padding-top="100px">(line 10 in the code)
is not doing anything. How to correct this?
Login.html
<ion-header>
<ion-navbar color="primary">
<div class="row">
<ion-title>Login</ion-title>
</div>
</ion-navbar>
</ion-header>
<ion-content padding>
<div padding-top="100px">
<form [formGroup]="loginForm" (submit)="loginUser()" novalidate padding id="loginForm">
<ion-item id="loginItem_1">
<ion-label stacked id="loginLable">Email</ion-label>
<ion-input #email formControlName="email" type="email" placeholder="Your email address"
[class.invalid]="!loginForm.controls.email.valid &&
loginForm.controls.email.dirty" color="secondary">
</ion-input>
</ion-item>
<ion-item class="error-message" *ngIf="!loginForm.controls.email.valid &&
loginForm.controls.email.dirty" id="loginItem">
<p id="loginLable">Please enter a valid email.</p>
</ion-item>
<ion-item id="loginItem_2">
<ion-label stacked id="loginLable">Password</ion-label>
<ion-input #password formControlName="password" type="password" placeholder="Your password" color="secondary">
</ion-input>
</ion-item>
<button ion-button block type="submit" id="loginButton">
Login
</button>
</form>
</div>
<button ion-button block clear (click)="goToResetPassword()">
I forgot my password
</button>
<button ion-button block clear (click)="createAccount()">
Create a new account
</button>
</ion-content>
<ion-footer>
<ion-toolbar color="primary">
<ion-title>Created By</ion-title>
</ion-toolbar>
</ion-footer>
View
Don't use inline styles. Which is very very BAD.
You can try as shown below.
page.html
<div class="padding-top-100">
</div>
page.scss
.padding-top-100 {
padding-top:100px;
}
Inline CSS needs to be defined in the style HTML attribute like so:
<div style="padding-top: 100px;">
There is no "padding-top" attribute hence why it's not doing anything
I would recommend giving that div an id / class and targeting it with CSS instead, makes it easier to manage (Ionic comes with basic styling by default)
Try using this:
<ion-content padding="true">
You can see the example on this website :
http://ionicframework.com/getting-started

Why are my buttons going out of screen in my Ionic app?

I have created a simple chat form in Ionic.
Problem: Buttons are going out of screen.
It looks like this this -
My chat.html
<ion-header>
<ion-navbar>
<ion-title>communicationgiven</ion-title>
<button ion-button (click)="close()" style="margin-left: 90%;margin-top: -3%">Close</button>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<div>
<p *ngFor="let list of list; let i = index;">
<ion-item>
<!-- <p style="color: #1bb0f4;font-size: 20px;">Tagto {{list.TAG_TO}}</p> -->
<p style="color: #1bb0f4;"> {{list.TAG_FROM}}</p>
<p style="color: #d2dce1;"> {{list.TAG}}</p>
</ion-item>
</p>
</div>
</ion-list>
</ion-content>
<ion-footer class="footer">
<form #com="ngForm" (submit)="onsubmit(com.value)">
<ion-input placeholder="TAG" type="text" name="TAG" ngModel ></ion-input>
<button ion-button type="submit" style="margin-left: 90%;margin-top: -5%;">Submit</button>
</form>
</ion-footer>
I want to know why my buttons are going out of the page; how can I make sure they stay inside the screen, irrespective of the screen size?
What is the best practice here? I am fairly new in CSS.
You have to use below code for left button
<ion-header>
<ion-navbar>
<button ion-button icon-only menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>
Page Title
</ion-title>
<ion-buttons end>
<button ion-button icon-only (click)="openModal()">
<ion-icon name="options"></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
For footer you can use ion-grid
<ion-footer class="footer">
<form #com="ngForm" (submit)="onsubmit(com.value)">
<ion-grid>
<ion-row>
<ion-col col-9>
<ion-input placeholder="TAG" type="text" name="TAG" ngModel ></ion-input>
</ion-col>
<ion-col col-3>
<button ion-button type="submit">Submit</button>
</ion-col>
</ion-row>
</ion-grid>
</form>
</ion-footer>
For more info please refer this
https://ionicframework.com/docs/api/components/toolbar/Navbar/
you had given style="margin-left: 90% that is margin from left side is 90% so obviously it will go out of screen, try to decrease the value.
It's hard to answer this one as I can't replicate the issue locally with what you've provided.
I'd start by reducing the margin-left: 90% on the button element, see how that goes.
In regard to best practices, an important one is to not use inline styles. That is putting styles in the style html attribute. Instead try using an external style sheet or at least an internal style sheet, see: https://www.w3schools.com/css/css_howto.asp

ionic angular styling based on json

İ m trying to change the item color. Css is not working or i m missing something else?
<ion-view title="Add order to a table">
<ion-content class="has-header has-subheader">
<ion-list>
<ion-item ng-repeat="table in tables" type="item-text-wrap" class="item-avatar"
href="#/app/tables/{{table.id}}">
<div ng-class="{table.Status === '0': 'red'}">
{{table.Tablename}} - {{table.Status}}
<p ng-class="radio-high">dfsa</p>
</div>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
You have to do it like this as in Stackhelpers answer but the table.Status has to be capitalised or it will not work:
<ion-view title="Add order to a table">
<ion-content class="has-header has-subheader">
<ion-list>
<ion-item ng-repeat="table in tables" type="item-text-wrap" class="item-avatar" href="#/app/tables/{{table.id}}">
<div ng-class="{ 'red' : table.Status === 0 }">
{{table.Tablename}} - {{table.Status}}
<p ng-class="radio-high">dfsa</p>
</div>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
ng-class="{ 'red' : table.status === 0 }"
Please try and share your observations

How to do sidemenu as a overlay in ionic?

I'm new to ionic framework. I need to follow ionic tags to do sidemenu overlay. Please help me.
The default style of sidemenu gives only drag style but i need the side menu as a overlay.
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<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>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
It's a toggleable side menu. If you want an overlay unfortunately you'll have to make your own.

in ionic, when swipe back, the nav bar become blank

the parent page:
<ion-view view-title="my account" >
<ion-nav-bar class="bar-assertive" align-title="center" ></ion-nav-bar>
<ion-content >
<ion-list>
<ion-item>
<ion-item class="item-remove-animate item-icon-left item-icon-right" type="item-text-wrap" ui-sref="tab.modipass">
<i class="icon ion-ios-unlocked-outline"></i>
<div>company profile</div>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
the child page:
<ion-view view-title="about company" on-swipe-right="closePage()">
<ion-nav-bar class="bar-assertive" align-title="center">
<ion-nav-buttons side="left">
<button class="button button-clear button-light" ng-click="closePage()">
<i class="ion-ios-arrow-back" style="font-size:20px"></i>
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content class="padding">
<ul class="list">
<li class="item item-text-wrap item-borderless">about company</li>
</ul>
</ion-content>
</ion-view>
both the parent page and the child page have nav-bar, they have the same assertive color and different title.
when swipe from child back to parent, the child page nav bar becomes blank,no title,no color. the parent page nav bar is normal.
the above situation only happens when swiping.
Please help to check why?
I think it's a bug on Ionic, now I solved it by adding a CSS class
ion-nav-bar.hide {
display: block !important;
}
Remember that is a workaround, follow this issue to tracking the fix.

Resources