What is the process for creating a default button in Ionic framework?

Recently, I developed an app that includes a survey page. Each question in the survey has two buttons for the user to select: Yes or No.

However, as a newcomer to using Ionic, I encountered an issue after building the code and checking the output. One of the buttons appears to be in a clicked state by default, which is not the desired behavior. In the screenshot below, you can see the current situation when the app runs. Ideally, the buttons should be clickable and have a white background. I'm seeking assistance with this matter as I still find it confusing to work with Ionic.

https://i.sstatic.net/M2dUZ.png

Below are the snippets of code I utilized:

.html -edited

 <ion-row>
    <ion-col size-md = "6">
      <ion-button (click)="onYesQ1()" [ngClass]="enoughTime ==='Yes' ?'btn-pressed':'btn-unpressed'"  [class]="btn-pressed" fill = "clear">
        <div class = "parentElement">  
      <img src = "{{myYesImage|staticpath}}"/>
    <br><br><p class = "btn-work"><b>Yes</b></p>
        </div>
      </ion-button>
      <ion-button (click)="onNoQ1()" [ngClass]="enoughTime ==='No' ?'btn-pressed':'btn-unpressed'" class="" fill = "clear">
        <div class = "parentElement">
         <img src = "{{myNoImage|staticpath}}"/>
         <br><br><p class = "btn-work"><b>No</b></p>
        </div>
      </ion-button>
    </ion-col>
  </ion-row>

.scss

.btn-pressed{
vertical-align: middle;
width: 126px;
height: 90px;
left: 35.7px;
background: #0E82C1;
border: 1px solid #979797;
box-sizing: border-box;
box-shadow: inset 0px 1px 5px 1px rgba(0, 0, 0, 0.3);
border-radius: 23px;
color: white;

}

.btn-unpressed {
  vertical-align: middle;
  width: 126px;
  height: 90px;
  left: 35.7px;
  border-radius: 25px;
  box-shadow: 0px 0px 19px rgba(0, 0, 0, 0.12), 0px 10px 24px rgba(0, 0, 0, 0.24);
  }

.ts -edited

        @Input() enoughTime : string = "";

Error:

https://i.sstatic.net/paLlL.png

Answer №1

Kindly adjust your code as mentioned below. The issue is not with ionic, but rather with your logic.

.ts file

@Input() availableTime : string = "";

.html file

<ion-row>
    <ion-col size-md = "6">
      <ion-button (click)="onYesQ1()" [ngClass]="availableTime ==='Yes' ?'btn-pressed':'btn-unpressed'"  [class]="btn-pressed" fill = "clear">
        <div class = "parentElement">  
      <img src = "{{myYesImage|staticpath}}"/>
    <br><br><p class = "btn-work"><b>Yes</b></p>
        </div>
      </ion-button>
      <ion-button (click)="onNoQ1()" [ngClass]="availableTime ==='No' ?'btn-pressed':'btn-unpressed'" class="" fill = "clear">
        <div class = "parentElement">
         <img src = "{{myNoImage|staticpath}}"/>
         <br><br><p class = "btn-work"><b>No</b></p>
        </div>
      </ion-button>
    </ion-col>
  </ion-row>

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

How to send a value to a function in Angular from a different function?

Within my Angular Typescript file, I am working with two functions named data and lists. My goal is to pass the variable windows from the function data to the function lists. However, when attempting to call the function lists, I encounter an error: Canno ...

Restrict the size of an image within a div by setting a maximum height and allowing the width

While this code snippet functions perfectly in WebKit browsers, it encounters issues when used in IE and Firefox. Unfortunately, due to other necessary functionalities, using the img tag is essential, making background-image an unviable option. Code Snipp ...

Changing the style of Vuetify v-list-item when hovering over it

I just started using Vuetify and I came across a v-list sample that I need help with. Here is the link to the Vuetify v-list sample on Github. My v-list: https://i.sstatic.net/ykTIi.jpg Code: <template> <v-card max-width="500" class= ...

Applying personalized CSS to an element based on the condition of a child element in the previous sibling element

I am trying to apply styles to a span element only when a child element in a preceding sibling div element is active, which means a radio button has been checked. I am unable to modify the code and can only use CSS for this task. Any ideas on how to achi ...

When combining <a> with the class line-through, the line does not appear

I am currently utilizing a class to replace the deprecated strike in HTML: .entfall { text-decoration: line-through; } However, when using Firefox 38.x and the following code: <span class="entfall"><a href="some link">text</a></span ...

The type 'SVGPathSeg' cannot be assigned to type 'EnterElement' because the property 'ownerDocument' is not present in type 'SVGPathSeg'

I'm attempting to replicate this example using the d3-ng2-service service on Angular 5. Component: OnInit code: let d3 = this.d3; let d3ParentElement: Selection<HTMLElement, any, null, undefined>; let d3Svg: Selection<SVGSVGElement, any, n ...

Ways to modify the gap between buttons using CSS

I am faced with a design challenge on my home page. I want to add some spacing between the buttons so they are not too close to each other, but for some reason margin-top and margin-bottom properties are not working as expected. Can you help me figure out ...

Generate a dynamic vertical line that glides smoothly over the webpage, gradually shifting from one end to the other within a set duration using javascript

I have designed a calendar timeline using html. My goal is to implement a vertical line that moves from left to right as time progresses, overlaying all other html elements. This functionality is similar to Google Calendar's way of indicating the curr ...

Fixing the alignment of the left column table in Bootstrap 3.3.7

Is there a way to fix the left table column (date and all column names) in Bootstrap 3.3.7? I attempted to use position: fixed; but it didn't work as expected. Any suggestions on what I should do next? Check out this fiddle for reference <scr ...

Repeated Hover Effects on CSS Menu Icons

the webpage I need help with is (issue with general menu drop down) Hello I recently decided to enhance my menu by incorporating icons. I had successfully implemented a drop-down menu using only HTML and CSS, but when I attempted to add icons next to ea ...

Break up in the middle of a sentence: Material UI

Currently facing an issue where my sentences break in the middle. Working with Material UI requires manual styling of different components like MUI. The problem I'm encountering can be seen below. I tried removing the display: flex, but then the squar ...

Trouble with applying position absolute to pseudo element in Firefox version 12 and higher

I seem to be running into an issue with the positioning of a pseudo element in Firefox version 12 or higher (possibly even earlier versions). Despite having position:relative on the anchor tag, the element appears to be relative to the entire page. Any ide ...

The IE browser is showing a blank page when I try to open my Angular 8 application

Even after incorporating all the necessary polyfills and making updates to the browserlist file and tsconfig file, I am still unable to identify a solution. Any assistance would be greatly appreciated. ...

Capybara - Navigating a page by clicking on a link related to another value

I'm currently facing a challenge in locating and selecting a particular link on a web page. All links within an HTML table contain the term 'Edit' (it's a link for editing configuration settings). However, the exact link changes depend ...

Oops! Looks like we encountered an issue: Unable to locate a differ compatible with the object '[object Object]' of type 'object'. NgFor can only bind to Iterables in

Greetings everyone, I am facing an issue with the following error message: ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables I have attempted using .json bu ...

Angular: Smooth transitions for ngif animations - Learn how to animate ngif elements seamlessly as one element is removed from the DOM

Is there a way to delay the execution of ngIf? I have a scenario where elements in a parent component fade out and are removed from the DOM using ngIf, followed by elements from a child component coming in. However, I am facing an issue with elements overl ...

Troubleshooting HTML Label Problems

I am facing an issue with my custom labels. .label-ras{ padding:3px 10px; line-height:15px; color:#fff; font-weight:400; border-radius:5px; font-size:75%; } .label-primar{background-color:#5c4ac7} <span style="background- ...

A see-through section with a border that fades in transparency

Can anyone help me with creating a box with a unique design using CSS only? I want the box to have a rounded border that starts at 80% opacity at the top and gradually fades to 20% opacity at the bottom. Additionally, the border should start at 80% opaque ...

When you refresh the page, the number of items in the cart displayed on the navbar always shows 0

When using my angular application, I encountered a problem with adding movies to a cart. Although I can successfully add them to the cart and see the correct number of movies reflected in the navbar, upon refreshing the page, the count resets to 0. Here i ...

Center the font in the middle of the text field

I'm having a text field with a jQuery hint. How do I align the font to be in the middle? I've attempted using vertical-align: middle but it doesn't seem to work. <style type="text/css"> #name { border: 1px solid #c810ca; heig ...