Ionic: Fixed button located at the bottom of a specific ion-slide

I've been creating a series of slides with questions, and the final slide serves as a summary of the previously answered questions. I want to ensure that the submit button is always visible at the bottom of this last slide. However, I've encountered some challenges in achieving this:

  • Using an ion-fab-button, but it doesn't remain fixed.

  • Applying CSS with "position: sticky !important;" to the button.

  • Wrapping everything except the button in an ion-card-content.

<ion-slide>
    <ion-card>
      <h1>Questions Overview</h1>
      <ion-list *ngFor="let question of questions">
        <ion-item>
          <ion-label>
            Question: {{ question.question }}
          </ion-label>
        </ion-item>
        <ion-item>
          <ion-label>
            Your Answer: {{ question.answer }}
          </ion-label>
        </ion-item>
      </ion-list>
      <ion-button (click)="onSubmit()" expand="full">Submit</ion-button>
   </ion-card>
</ion-slide>

As I'm still relatively new to the framework, I'm unsure if there are other potential solutions to explore. I have searched online, but most resources discuss buttons outside of ion-content, which doesn't align with my needs as all elements are within ion-content. Placing the button outside ion-content would result in it appearing on every slide, which is not the desired outcome.

Update:

TL;DR Workaround:

Add

@ViewChild('slides', {read: IonSlides}) slides: IonSlides;
in the .ts file

Utilize the event (ionSlideReachEnd)="onEnd()" on <ion-slides> in the .html file

onEnd() {
  this.slides.isEnd().then(endReached => { 
  this.reachedEnd = endReached // reachedEnd is a variable to be checked in the HTML file
}

To address this issue, I have implemented a workaround. By using the above code, I am able to determine when I reach the end of the slides. Subsequently, I display an ion-footer containing the submit button. This footer remains fixed at the bottom of the page rather than being tied to the slides, ensuring that users can always submit their answers regardless of the slide they are on.

Answer №1

To easily control the visibility of a button based on certain conditions in Ionic, we can use a simple *ngIf directive. In this case, we want the button to only be visible on the last slide of our array. Since the index of the last slide will be equal to the length of the array -1, we can set the condition as follows:

<ion-button *ngIf='idx==questions.length-1' (click)="onSubmit()" expand="full">Submit</ion-button>

Here is the relevant HTML code snippet:

<ion-content padding>

    <ion-slides>
        <ion-slide *ngFor="let question of questions; let idx = index">
            <ion-card>
                <h1>Questions Overview</h1>
                <ion-list>
                    <ion-item>
                        <ion-label>
                            Question: {{ question.question }}
                        </ion-label>
                    </ion-item>
                    <ion-item>
                        <ion-label>
                            Your Answer: {{ question.answer }}
                        </ion-label>
                    </ion-item>
                </ion-list>
                <ion-button *ngIf='idx==questions.length-1' (click)="onSubmit()" expand="full" style='border:2px solid red;padding:5px; margin:5px; background:lightpink; position: absolute; bottom: 0%; left:50%; margin-left:-17px'>Submit</ion-button>
            </ion-card>
        </ion-slide>
    </ion-slides>

</ion-content>

For a live example, feel free to check out the stackblitz demo provided in the about tab here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Upon successful Google login, Angular 2 fails to initiate the callback function

import {Component,Directive,OnInit,NgZone} from 'angular2/core'; declare const gapi:any; declare const $:any; @Component({ selector: 'mysite', templateUrl:'./app/template.html' }) export class Test{ userAuthToken; ...

Guide to incorporating Moengage into Node.js APIs for delivering email notifications based on user interactions

How can Moengage be integrated into Node Js APIs for sending notifications to users based on user events? I have reviewed the Moengage API documentation but did not find relevant information on integrating Moengage with Node Js APIs. Is there a step-by-s ...

Mapping type property names in Typescript for substitution

I am working on a function that accepts two objects as parameters: one representing a model and the other representing a mapping. The function then returns an object with two properties: one showing the base model and the other displaying the model with ea ...

Create a circular shape using CSS that dynamically adjusts its size to match the width

Can you help me with a CSS challenge? I need to create circles around elements on a webpage, but my code is not working perfectly. The width of the circle is off and I can't seem to center it properly. The width does not match the content (it is alw ...

What is the best way to align a Font Awesome icon within an SVG circle?

Can anyone help me position the trophy inside the circle, just below the number 2000? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7974746f686f697a6b5b2e352835 ...

Dealing with Scoping Problems in a Typescript d3 Update Tutorial

I'm facing challenges trying to implement the provided bl.ocks example in Typescript (using Angular). This is my implementation in TypeScript: StackBlitz Could anyone offer insights on what might be causing the issues I'm encountering? My initi ...

What is the best way to make sure images and text are properly aligned for different screen sizes

I'm a beginner with Bootstrap and could use some assistance. In my code, I have text and images divided into four columns with alignment set based on screen size using media queries in CSS. However, when resizing the window to tablet view (check Scre ...

Is there a way to update the content of both spans within a button component that is styled using styled-components in React?

I am interested in creating a unique button component using HTML code like the following: <button class="button_57" role="button"> <span class="text">Button</span> <span>Alternate text</span> ...

Type '{}' is lacking the subsequent attributes in type 'Record'

This is the code snippet I am working with: const data : Record<MediaType, Person[]> = {}; I encountered an error while initializing the 'data' object as shown above. The error message specifies that certain properties are missing from typ ...

Angular modal not progressing past initial message due to Bootstrap integration issue

The modal functionality only seems to be working for the first message I send, as subsequent messages do not appear. My environment includes: Angular 17 Bootstrap 5.3 This is the TypeScript file snippet: import { Component } from '@angular/core&apos ...

Is there a way to hide the blinking cursor at the conclusion of the animation after 3 seconds?

I've been working on this HTML snippet <div class=typewriter> <h1>Lorem Ipsum</h1> </div> and included some CSS styles as well .typewriter { display: inline-block; } .typewriter h1 { overflow: hidd ...

Building Interface/Type with Static Properties and Constructor Signature in TypeScript

I am looking to devise an interface or a type that contains static properties and a constructor signature. My goal is to utilize this interface/type as a parameter for a function. I experimented with using an interface, but encountered limitations in decla ...

How to iterate through properties declared in an Interface in Angular 12?

Before Angular 12, this functioned properly: export interface Content { categories: string[] concepts: Topic[] formulas: Topic[] guides: Topic[] } //this.content is of type Content ['formulas', 'concepts'].forEach(c =&g ...

Full-screen background with image adhering perfectly - left-aligned button that stays in place

Excuse me if my question seems basic, as I am just starting out in front-end development and may not know all the necessary terms to fully understand existing questions. I currently have a simple html file that consists of a title and three buttons, with ...

Ways to eliminate unused classes from JQuery UI

We have successfully implemented JQuery UI library for enhancing our interface. However, since we no longer need to support outdated browsers like IE6, classes such as .ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl are unnecessary and clu ...

The CSS property for fixing an element in place: position

On my website, I have a position:fixed <div> that appears in the center of the screen. Whenever there are messages, a second position:fixed <div> is displayed next to the first one. I've noticed that on various screen sizes, like a netbo ...

Error code 2532 occurs when trying to access an object using square brackets in TypeScript

Encountered the ts error: Object is possibly 'undefined'.(2532) issue while trying to access the value of a field within an object, where the object key corresponds to a value in an Enum. Below is a concise example to showcase this problem: en ...

I am interested in utilizing the request-reply pattern with KafkaJS in a TypeScript environment. Could you provide guidance on how to successfully implement this?

I am new to Kafka and I am trying to implement the request-reply pattern using kafkajs in TypeScript. However, my current implementation is very basic and the consumers inside producers are taking too long to start, causing delays. Is there a better way to ...

Guide on enabling the Access-Control-Allow-Origin feature for Angular 5 and Node.js:

After exploring various methods to include 'Access-Control-Allow-Origin', I have not been successful in resolving the issue. I am utilizing the @angular/common/http module with an external URL as a data source. However, when attempting to retrie ...

I receive an [object HTMLCollection] as the output

I am currently working on recreating a login page and I want it so that when the button is clicked, it displays the name you entered, but instead, it returns [object HTMLCollection]. My expectation was to have the name displayed as entered. var nombre ...