Icons that are clickable in ionic

I have successfully created a list card with 2 icons in each row. However, I am facing a challenge in making these icons clickable without disrupting the layout of the list. I attempted to add an ng-click to the icon element, but it did not work as expected. Additionally, surrounding the icons with a div caused me to lose the original layout of the list.

<div class="list card">
  <div ng-repeat="destination in destinations | isActive">
    <div class="item item-divider">
      <span>{{title}}</span>
    </div>
    <a href="#" class="item item-icon-left item-icon-right item-balanced">
      <i class="icon ion-ios-home"></i>
      <div>
        <div>{{text1}}</div>
        <div><b>{{text2}}</b></div>
        <div>{{text3()}}</div>
        <div>{{text4()}}</div>
      </div>
      <i class="icon ion-ios-filing"></i>
    </a>
  </div>
</div>

My goal is to maintain the current layout with the two icons positioned on the left and right sides.

Answer №1

Transform the link tag into a div tag, and change your i tag to a link tag. Don't forget to include some CSS for the icon styling. All set!

(See Demo)

HTML

<div class="list card">
    <div ng-repeat="destination in destinations | isActive">
        <div class="item item-divider">
            <span>{{title}}</span>
        </div>
        <div class="item item-icon-left item-icon-right item-balanced">
            <a href="#" class="icon ion-ios-home"></a>
            <div>
                <div>{{text1}}</div>
                <div><b>{{text2}}</b>
                </div>
                <div>{{text3()}}</div>
                <div>{{text4()}}</div>
            </div>
            <a href="" class="icon ion-ios-filing"></a>
        </div>
    </div>
</div>

CSS

.icon {
    color: inherit;
    text-decoration: none;
}

Answer №2

When working with Ionic 3, you can use the following code snippet:

<ion-card class="border-top" (click)="eventDetail(event.id)">
        <ion-card-content>
          <ion-card-title>
            {{ event.title }} <ion-badge color="primary"> {{ event.date | date : "MMMM d, yyyy - HH:mm"}}</ion-badge>
          </ion-card-title>
          <p>
            {{ event.description }}
          </p>
        </ion-card-content>
      </ion-card>

In this example, eventDetail is a function within the corresponding class and eventId is the value being passed.

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

Update the HighChart Pie chart depending on the selection in the dropdown menu

Currently, I am working on creating a pie chart using data retrieved from a web socket in JSON format. Once the JSON object is returned, if the user selects the "Pie Chart" option, another Select dropdown will be displayed to choose a specific time period. ...

Tips for appending the id of an active element to a URL

My goal was to include the id value of the active element in a URL and then redirect to that URL with a button click. HTML <div class="icon" tabindex="0" id="company"> <img src="company.png"> </div> <button type="submit" onclick= ...

Why does one of the two similar javascript functions work while the other one fails to execute?

As a new Javascript learner, I am struggling to make some basic code work. I managed to successfully test a snippet that changes text color from blue to red to ensure that Javascript is functioning on the page. However, my second code attempt aims to togg ...

What is the best way to avoid using ng-repeat for the last item being shown?

I currently have an ng-repeat loop that is dependent on an ng-if condition. Here is the specific code block: <div class="fav-prod-customised> <p ng-repeat="ingredient in product.options" ng-if="ingredient.default_quantity == 0 & ...

Changing a field in AngularJS to set validity as true in a different way

After following the guidance provided in this answer to implement custom server-side validation for a unique email constraint, I encountered an issue with my submit function on the controller: function submit(form){ CompanyUser.save(vm.model) .suc ...

Don't waste time creating multiple popups for changing content - streamline your process

Challenge I've successfully extracted information from an array and displayed it dynamically in a tooltip/popup window above each photo on the page. However, with 56 different individuals at various locations, arranging them neatly in a grid poses a ...

Error: [$controller:ctrlreg] - The controller registration has failed

I am currently exploring the world of AngularJs and attempting to display options from a json file. However, I keep encountering the following error message: "Error: [$controller:ctrlreg]" Below is the code snippet I am working with: var sj = angular. ...

Easy jQuery image that smoothly fades in and out

Can anyone recommend a script that allows for creating a slideshow where images fade in and out, rather than sliding left and right? I have a list of images below that I would like to use for the slideshow. <ul class="slideshow"> <li><im ...

Create a table that allows one column to have ample space, while ensuring that the other columns have uniform widths

This HTML/CSS creation features the following: https://i.stack.imgur.com/R8PRB.png However, the challenge lies in making the Very Good, Good, Fair, Poor, Very Poor columns equal in width while still allowing the "question" column to adjust its width acco ...

Using AngularJS and SpringMVC for uploading multiple files at once

Having recently delved into the world of angularJS, I've been attempting to upload a file using angular JS and Spring MVC. However, despite my efforts, I have not been able to find a solution and keep encountering exceptions in the JS Controller. Bel ...

Discovering the exact distance between a 'li' and a 'div' element

Currently, I am in the process of converting HTML to JSON. Here is an example of the HTML I am working with: <div class="treeprofit" id="divTreeViewIncomeDetails" style="height: auto;"> <li><span class="fa fa-folder-open highlight" ...

Verify whether the user's email is registered in the database

I have a login form and I want to verify if a user's email exists in the database, but I'm not sure about the syntax for integrating Angular with Node. In my Main.js file, I have an ng-click on the submit button that triggers this function. I ex ...

Fetching data from the server using Angular and parsing it as JSON

Can anyone provide some insight on the best way to use jsonObjects in ng repeat? Here is my code: This is the response I get from PHP: die(json_encode(array('sts'=>'success', 'title'=>'*****', 'msg' ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...

Modifying the color of the tooltip arrow in Bootstrap 4: A step-by-step guide

How can I change the arrow color of the tooltip using Bootstrap 4? Here is my current code: HTML: <div class="tooltip-main" data-toggle="tooltip" data-placement="top" data-original-title="Service fee helps Driveoo run the platform and provide dedicate ...

Issue: Unable to use the b.replace function as it is not recognized (first time encountering this error)

I can't seem to figure out what I'm doing wrong. It feels like such a silly mistake, and I was hoping someone could lend a hand in solving it. Here is my controller - I'm utilizing ng-file-upload, where Upload is sourced from: .controller( ...

What could be the reason behind the failure of this :after element?

I am facing an issue with the preloader on my webpage where the animation is not displaying as expected. The animation should appear on top of a dark black background before the page fully loads, but it seems to be missing. The CSS for the animation works ...

AngularJS restricts inputs to be read-only

I'm facing an issue with readonly inputs in AngularJS. I have a select element that changes the values of readonly inputs through a script. However, when I attempt to display these values using ng-model in a table as {{ng-model}}, they don't appe ...

Is it possible to select a date from the datepicker, or should I move to the next month to find an

Protractor newbie here, attempting to test a date picker with Protractor. My attempt at selecting an available date: this.selectAvailableDate = element(by.css('td[aria-disabled="false"]')); If the desired date is not in the current month, I nee ...

Ways to implement a conditional statement to display a div using JavaScript

Looking for a way to utilize Javascript conditions to toggle the visibility of a div in an HTML5 document? Check out this code snippet below: #demo { width: 500px; height: 500px; background-color: lightblue; display: none; } To set the f ...