Try implementing ng-if or ng-switch to switch between two different href links in Ionic

In my current Ionic project, I am working on a feature that allows users to add drinks to their favorite list. These drinks are sourced from two different views: View 1 displays a general list of drinks while View 2 shows newly added drinks. Each view has its own detail page associated with it.

When a user navigates to the My Favorites view, they will see all of their favorite drinks from both View 1 and View 2. Clicking on a drink from View 1 should lead to a different URL compared to clicking on a drink from View 2.

Below is the code snippet for the Favourites view:

<ion-content class="padding">

    <div class="row responsive-md">
        <div class="col col-33">    
            <div>
                <!-- View 1 GENERAL LIST OF DRINKS -->
                <a href="#/app/gin-mixes-detail/{{drink.id}}" class="grid-gin-mixes" ng-repeat="drink in favs = (user.current.favorites) track by $index">
                    <img class="gin-mixes-placeholder" ng-src="{{drink.src}}">
                    <p>{{drink.title}}</p>
                </a>

                <!-- View 2 NEWLY ADDED DRINKS -->
                <a href="#/app/newly-added-detail/{{drink.id}}" class="grid-gin-mixes" ng-repeat="drink in favs = (user.current.favorites) track by $index">
                    <img class="gin-mixes-placeholder" ng-src="{{drink.src}}">
                    <p>{{drink.title}}</p>
                </a>
            </div>
        </div>
    </div> 
</ion-content>

I am looking for guidance on how to ensure that when a user clicks on a drink from View 2, the correct URL is used. Would using either ng-if or ng-switch be the best approach for this? How should I go about implementing it?

Answer №1

To streamline the process, there is no necessity for maintaining separate templates. Instead, utilize ng-href to conditionally display the href attribute using interpolation {{}}.

Code Snippet

ng-href="{{'#/app/'+(drinkType=='general'?'gin-mixes-detail':'newly-added-detail')+/drink.id}}"

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 reference a nested closure function in Javascript without relying on the 'this' keyword

I'm facing a situation where I have a tree of closures: 'A' contains private closures 'pancake' and 'B'. There are times when I need to call the private closure 'pancake' from inside 'B' and access its ...

passing a text value from PHP to a JavaScript function

Trying to pass a string retrieved from the database to a JavaScript function. In my PHP code, I have: <input type="image" name="edit_me" id="edit_me" value="<?php echo $row['id']; ?>" onClick="edit_chirp(<?php echo $row['id&ap ...

Transmit the value of radio button data to PHP using Ajax

I'm facing an issue in sending radio button data to PHP using JavaScript. For example, when the radio button "Mother" is selected, the value "Mother" should be sent via AJAX. However, I'm struggling to achieve this functionality and haven't ...

Euro currency formatting

I've been developing a component that formats input values in various currencies like Dollar and Euro, including commas and dots. Although my Dollar input works fine, I'm struggling with the Euro input as it doesn't generate the correct valu ...

WARNING: Alert raised due to the discovery of two offspring sharing identical keys, `${item}-${index}`

I have been facing the issue of receiving an error message 'ERROR Warning: Encountered two children with the same key, ${item}-${index}' and I am not sure what is causing it. Can someone please guide me on how to resolve this problem? Any help w ...

AngularJs array mapping is a powerful feature that allows you to

I am dealing with two arrays $scope.tags = [{ "id": 1, "name": "python" }, { "id": 2, "name": "NodeJs" }, { "id": 3, "name": "git" }] The second array is $scope.skillsInterested = [1,2]; What I am trying to achieve is: How do I match the IDs in$scop ...

Best practices for displaying a Multidimensional JSON Object using JavaScript

Within my current project, I have a JSON object structured as follows: { "face": [ { "attribute": { "age": { "range": 5, "value": 35 }, "gender": { "confidence ...

Why is my AngularJS application triggering two events with a single click?

<button id="voterListSearchButton" class="serachButton" ng-click="onSearchButton1Click()">find</button> This button allows users to search for specific information: $scope.onSearchButton1Click = function() { var partId = $("#partIdSearch" ...

Tips on concealing all classes except one through touch swiping

If you have a website with a single large article divided into multiple sections categorized as Title, Book1, Book2, & Book3, and you want to implement a swipe functionality where only one section is displayed at a time, you may encounter some issues. ...

Inquiries regarding the use of php in conjunction with react.js

As I dive into learning react.js, there are numerous questions swirling in my mind: Is PHP a prerequisite for learning React? How does PHP integrate with React.js and what purpose does it serve within PHP? If I already know PHP, is learning React essent ...

JavaScript function to calculate the sum of an array while excluding the highest and

I'm currently working on a challenging kata in codewars, but I'm encountering some difficulties. My goal is to calculate the sum of all elements in an array except for the highest and lowest values. This is my current implementation: function s ...

A function will not receive updated values due to an AJAX request

Currently, I am in the process of developing a JavaScript function that is responsible for altering the view of a postcard based on the selected case. The issue at hand pertains to the usage of old values from the object "m_case." Upon clicking the button ...

"Implementing a 2D graphical user interface on a three.js

Struggling to create a 2D graphical user interface on the renderer. The challenge lies in positioning the 2D GUI dynamically based on the width of an element drawn in threejs (the element has a width of X using threejs units, and the menu needs to be posit ...

Create a custom chrome browser extension designed specifically for sharing posts on

I'm working on creating a basic chrome extension that features an icon. When the icon is clicked, I want the official Twitter window to pop up (similar to what you see here). One common issue with existing extensions is that the Twitter window remains ...

jQuery UI Slider is malfunctioning (code example included)

I've implemented a jQuery UI slider on my website, and it's functioning quite well. You can check out the slider HERE. However, I've noticed that when I click on 'back to the top', the page smoothly scrolls up. But when I use the ...

My collection consists of objects arranged in this manner

let attributeSet = [{ "id": 1, "value": 11 }, { "id" : 1, "value": 12 }, { "id" : 1, "value" : 13 }, { "id": "2", "value& ...

Tips on converting deeply nested JSON into an excel file using Node.js

I am attempting to convert the JSON data below into an Excel file using XLSX. Although it successfully converts my JSON to Excel, I encountered an issue where the nested array of dailyPointsArray appears blank after conversion. Code Attempted const XLSX ...

Unit tests for an Angular2 service using Karma and Jasmine

api-connector.service.ts import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { ErrorObservable } from 'rxjs/observable/ErrorObservable'; import { Observable } from ...

Looking to extract data from JavaScript using Scrapy 1.4.0?

Apologies for my lack of proficiency in English. As a beginner in scrapy, I am seeking guidance on an issue I encountered while trying to scrape a particular website. Below is the code for my spider: import scrapy from bs4 import BeautifulSoup as bs clas ...

Having difficulty managing asynchronous functions with the useState hook in React

import React from "react"; import { UserContext } from "./../contexts"; import { removeStoredAuthData, storedAuthIsValid, storeNewAuthData, } from "./../utils/auth"; import { getUserInfos } from "./../api/userAuthen ...