Multiple buttons in footer in Ionic 3 - button

I am trying to add two buttons (left and right) in the footer section in Ionic 3 project. Either its coming side by side or in two different row. Following is my code.
<ion-footer>
<ion-buttons text-start>
<button ion-button clear (click)="backPage()">Back</button>
</ion-buttons>
<ion-buttons text-end>
<button ion-button clear (click)="nextPage()">Next</button>
</ion-buttons>
</ion-footer>
Following is the result

<ion-footer no-border text-center>
<ion-toolbar>
<ion-buttons left>
<button ion-button icon-only clear large (click)="formSlider.slideTo(0)">
<ion-icon name="skip-backward"></ion-icon>
</button>
</ion-buttons>
<ion-buttons right>
<button ion-button icon-only clear large (click)="formSlider.slideTo(formSlider.length() - 1)">
<ion-icon name="skip-forward"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-footer>

Use <ion-buttons start> or <ion-buttons end>
<ion-footer>
<ion-toolbar>
<ion-buttons start>
<button ion-button (click)="func1()"> Back
</button>
</ion-buttons>
<ion-buttons end>
<button ion-button (click)="func2()"> Next
</button>
</ion-buttons>
</ion-toolbar>
</ion-footer>

Related

How to make button and ion-title inline in ion-navbar in Ionic 3?

I need to show ion-button and ion-title same line in ion-navbar in ion-header. Below is my code.
<ion-header>
<ion-navbar>
<button ion-button icon-only>
<ion-icon name="arrow-back"></ion-icon>
</button>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
How to show ion-button and ion-title inline in ion-navbar ?
Try this:
<ion-header>
<ion-navbar>
<ion-buttons left>
<button ion-button icon-only >
<ion-icon name="arrow-back"></ion-icon>
</button>
</ion-buttons>
<ion-title text-left>Home</ion-title>
</ion-navbar>
</ion-header>
It is working properly.
In the latest Ionic (v5), the button position has changed to "slot" as shown below:
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>My Navigation Bar</ion-title>
</ion-toolbar>
</ion-header>
Additionally, there is a new ion-back-button which inserts a back button based on the history stack, etc.
Slot values are documented here: https://ionicframework.com/docs/api/buttons
Header documentation here: https://ionicframework.com/docs/api/header
you should use <ion-row> and <ion-col> labels. Use this:
<ion-header>
<ion-navbar>
<ion-row>
<ion-col col-5>
<ion-buttons left>
<button ion-button icon-only >
<ion-icon name="arrow-back"></ion-icon>
</button>
</ion-buttons>
</ion-col>
<ion-col col-5>
<ion-title text-left>Home</ion-title>
</ion-col>
</ion-row>
</ion-navbar>
It is really important use that to do your app responsive.

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

right align ion-select within ion-navbar

In the existing code the ion-select is seen just near the end of I want to place the ion-select at the right most position of the ion-navbar.
home.html
<ion-header >
<ion-navbar align-title="left" >
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-row>
<div>
<p style="color:white;">CoolManz!!</p>
</div>
<div >
<ion-item >
<ion-label>Gender</ion-label>
<ion-select [(ngModel)]="gender">
<ion-option value="f">Female</ion-option>
<ion-option value="m">Male</ion-option>
</ion-select>
</ion-item>
</div>
</ion-row>
</ion-navbar>
</ion-header>
This works for me in Ionic 3+
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-row>
<ion-title>Jobs</ion-title>
<ion-select [(ngModel)]="gender">
<ion-option value="f">Female</ion-option>
<ion-option value="m">Male</ion-option>
</ion-select>
</ion-row>
</ion-navbar>
</ion-header>

how to prevent responsive gride in ionic?

I would like to place 4 buttons in a row. However the buttons go to the next new line when tested on smaller screen devices. I would like to fix 4 buttons in one row and adjust the buttons sizes but not push the button to the next line.... how to do that?
<ion-grid>
<ion-row>
<ion-col col-25>
<!-- <button ion-button type="button" round small>House 1</button> -->
<button ion-button small round>create</button>
</ion-col>
<ion-col col-25>
<!-- <button ion-button type="button" round small>House 2</button> -->
<button ion-button small round>views</button>
</ion-col>
<ion-col col-25>
<!--<button ion-button type="button" round small>House 3</button> -->
<button ion-button small round>update</button>
</ion-col>
<ion-col col-25>
<!-- <button ion-button type="button" round small>House 4</button> -->
<button ion-button small round>delete</button>
</ion-col>
</ion-row>
</ion-grid>
Replace col-25 with col-md-3 like this,
<ion-grid>
<ion-row>
<ion-col col-md-3>
<!-- <button ion-button type="button" round small>House 1</button> -->
<button ion-button small round>create</button>
</ion-col>
<ion-col col-md-3>
<!-- <button ion-button type="button" round small>House 2</button> -->
<button ion-button small round>views</button>
</ion-col>
<ion-col col-md-3>
<!--<button ion-button type="button" round small>House 3</button> -->
<button ion-button small round>update</button>
</ion-col>
<ion-col col-md-3>
<!-- <button ion-button type="button" round small>House 4</button> -->
<button ion-button small round>delete</button>
</ion-col>
</ion-row>
Hope that helps

Place button to the center oh the toolbar ionic 2

I need to put a button in the center of my toolbar, and i have a menutoggle to the left. Here is my code :
<ion-toolbar>
<button ion-button icon-only menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-buttons end>
<button ion-button icon-only class="button-navbar">
<ion-icon name="ios-refresh"></ion-icon>
</button>
<button ion-button icon-only class="button-navbar button-right">
<ion-icon name="ios-cart-outline"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
With this i have my togglemenu and the two icons on the right, i would like one in the middle of the toolbar :
Thank you in advance !
I manage it by using the ion-title attribute :
<ion-header>
<ion-toolbar>
<button ion-button icon-only menuToggle class="pink">
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>
<button ion-button icon-only class="button-navbar pink" id="nobackground">
<ion-icon name="ios-refresh"></ion-icon>
</button>
</ion-title>
<ion-buttons end>
<button ion-button icon-only class="button-navbar pink">
<ion-icon name="ios-cart"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
and center in the CSS :
ion-title {
text-align: center;
}
.pink {
color: #F63566;
margin: auto;
}
don't forget to put margin auto on the icon :)

Resources