Using jQuery to bind data to Angular's *ngFor directive

I am currently in the process of customizing a horizontal timeline resembling https://codepen.io/ritz078/pen/LGRWjE/. The demo includes hardcoded dates which I want to replace with an array of Dates (timelineParsedDates)

<ol>
    <li><a href="#0" data-date="16/01/2014" class="selected">16 Jan</a></li>
    <li><a href="#0" data-date="28/02/2014">28 Feb</a></li>
    <li><a href="#0" data-date="20/04/2014">20 Apr</a></li>
    <li><a href="#0" data-date="20/05/2014">20 May</a></li>
    <li><a href="#0" data-date="09/07/2014">09 Jul</a></li>
    <li><a href="#0" data-date="30/08/2014">30 Aug</a></li>
    <li><a href="#0" data-date="15/09/2014">15 Sep</a></li>
    <li><a href="#0" data-date="01/11/2014">01 Nov</a></li>
    <li><a href="#0" data-date="10/12/2014">10 Dec</a></li>
    <li><a href="#0" data-date="19/01/2015">19 Jan</a></li>
    <li><a href="#0" data-date="03/03/2015">3 Mar</a></li>
    <li *ngFor="let parsedDate of timelineParsedDates; let index = index;">
        <a  href="#0" data-date="parsedDate">{{parsedDate}}</a>
    </li>
<ol>

Upon inspecting the browser console, it initially displays the last hardcoded date (03/03/2015) followed by a dynamically generated list item with an anchor tag. The value for {{parsedDate}} is correctly displayed, however, the data-data=" " interprets this as a string causing issues with the logic https://i.sstatic.net/z7wSJ.png

When attempting

data-date={{parsedDate}}

The following error occurs:

Template parse errors: Can't bind to 'date' since it isn't a known property of 'a'. ("<li *ngFor="let parsedDate of timelineParsedDates; let index = index"> <a href=\"#0\" [ERROR ->]data-date={{parsedDate}}>{{parsedDate}} </li>

If anyone has suggestions on how I can dynamically load these values into the data-data property, it would be greatly appreciated. I understand that mixing Angular with jQuery is not ideal, but this specific horizontal timeline design stood out to me. Additionally, I am relatively new to jQuery and struggling to find relevant resources on S/O, hence seeking advice here. Thank you in advance.

Answer №1

If you want to experiment with Angular attribute binding, consider using the following syntax:

[attr.data-date]="parsedDate"

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

Tips for retrieving information from a Vuetify modal window

Is it possible to retrieve data from a dialog in the VueJS Vuetify framework? Specifically, how can I access the username or password entered in the NewUserPopup.vue dialog from app.vue? App.vue = main template NewUserPopup.vue = Dialog template imported ...

What is the correct way to specify Tesseract options for page segmentation?

I've been trying to understand how to configure tesseract options for page segmentation. I attempted to use tessedit_pageseg_mode: '1', but encountered a halt in the text recognition process. If I input it as number 1, the process completes, ...

Tips for removing a specific dynamic element in HTML using an Angular reactive form

I successfully implemented a dynamic reactive form that allows users to add or delete fields dynamically. However, I am facing an issue with removing the Radio Button (And / Or) from the last row. I would like it to only appear for the first and second row ...

Tips for preventing repetition of code in multiple entry points in Rollup

My goal is to use rollup to process a group of input files and generate multiple output files in the dist directory that all have some common code shared between them. Below is my current rollup configuration: import path from 'path'; import pat ...

Angular2's asynchronous data binding is still lagging even after the data has been successfully loaded

I have integrated Firebase with Angular2 to retrieve an object. import { Component, OnInit } from '@angular/core'; import { AngularFire, FirebaseObjectObservable } from 'angularfire2'; import { ActivatedRoute, Params } from '@angu ...

comparing jquery version 1 and jquery version 3 backward-compatible browsers

It has come to my attention that jquery 2.x does not offer support for legacy browsers. If I wish to accommodate those outdated Internet Explorer versions, I must resort to using jquery 1.x. However, I am curious about jquery 3.x. Does it provide support ...

Determine the data type of an individual attribute within a collection of classes

I am working with a series of classes that have a body property defined within them. Here is an example: class Foo { body: {foo: string} constructor(body: Record<string, string>) { this.body = { foo: body.foo } } } class Bar { body: {ba ...

Getting the logged in user's ID in Angular using MongoDB and Node.js for the backend

How can I retrieve the logged user's ID so that when they click on "My profile", they are directed to url/profile/theirId? Thank you for your help! Below is my authentication.service code: export interface UserDetails{ username: string email: stri ...

Press the Enter key to generate a new table row

I have been dynamically creating an HTML table. Each row contains two columns created through a recursive call. Currently, a new row is generated by clicking on the second cell, but I want to switch this action to the "Enter" key press. Although my code su ...

How to delay setting a property in Angular 2 until the previous setter has finished execution

Hey there, I'm facing an issue with my component. Within my component, I have an input setter set up like this: @Input() set editStatus(status: boolean) { this.savedEditStatus = status; if (this.savedEditStatus === true && this.getTrigg === t ...

Invoking the asynchronous function Subscription within the ngOnInit lifecycle hook of a component

retrieving data from my service without waiting for it to complete. This is the Component responsible for fetching data for my grid. The issue lies in this part: this.store.loadRequestHistory(this.id). When hovering over store, no data is displayed from i ...

Angular4 does not recognize this.form.get as a valid function

While working on my Angular 4 application, I encountered an issue with data binding to a form. Despite the code for binding appearing correct, there seems to be a problem that I can't quite pinpoint. Upon debugging the application, I noticed that the ...

Error loading ngsw-worker.js in Angular 7

Issue An app that utilizes a Service Worker is experiencing problems. The app was recently upgraded from Angular 6.1 to version 7. Upon uploading the updated files to the server, an error message is displayed: https://i.sstatic.net/B7uPf.png Error Det ...

"Troubleshooting Issue: jQuery dataTables Filter Functionality Inoperative When Conjoined with

Incorporating the dataTables plugin and recycling code from another page to create a select for filtering a specific column, I encountered issues with the filtering functionality not working as expected. This was perplexing since it was code that had previ ...

React-Redux button unit test in Vitest encounters failure

I'm struggling with passing a button click test in my app component using Vitest, react-testing-library, and jest dom. As a newcomer to unit testing, I'm having difficulty figuring out how to make my test for the submit button in my form function ...

Using Jquery to Retrieve Deferred with Additional Objects from a Function

Here is a function that I am working on: function retrieve_modifications_as_objects() { var deferred = $.Deferred(); //Perform some operations..... return { current_values : actual_lov_values, updated_values : new_lov_values, removed_values ...

Is there a way to test the syntax of mocking a service in Angular 2 to call a local json-server instead of a remote endpoint?

I am currently working on writing a unit test to verify that a property in my Angular 2 component is populated after a service call that returns a promise. Within my component, there is a method: getListItems() { this.employeeService.loadEmployees(). ...

Clicking on a button will allow me to select only a portion of text within a specific cell of

Inside a table, there is a paragraph of text enclosed in a <td></td> element. Take for example the following passage. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard ...

What could be causing the abrupt termination of the ajax request?

Currently, I am making an ajax request to the server $.ajax({ type: "POST", data: checkin_push, url: api_url + 'file.php?token=' + last_token + '&date=' + dated, dataType: "json", timeout: 100000, // 100 seconds ...

Troubleshooting issue with applying hover effect to child divs

How come when I hover over one of the child items in my parentDiv, the background of the last childDiv changes no matter which child I place my mouse on? for (let i = 0; i < Number(height); i++) { for (let j = 0; j < Number(width); j++ ...