Slideshow through each item using Typescript and Angular8

I came across a solution in this carousel on by one link, but I'm struggling to work with the jQuery code even though I have JQuery installed in my project. For example:

const next = jQuery(this).next();

I am looking to convert the JQuery code from the link to Angular's jQuery library or achieve the same outcome using Typescript. Which method of the lifecycle hooks in Angular should I implement it in (OnInit, AfterViewInit,...)?

$('.carousel .item').each(function(){
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));

  if (next.next().length>0) {
    next.next().children(':first-child').clone().appendTo($(this));
  }
  else {
    $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});

Thank you

<div class="row">
              <div class="col-md-1" *ngIf="val">
                <span class="dot">
                  <button type="button" (click)="openModal1()" class="btn btn-default btn-circle btn-xl "><i
                      class="fa fa-history "></i></button>
                  <label class="carousel-label"> Modal 1</label>

                </span>
              </div>
              <div class="col-md-1" *ngIf="val === 'label 1'">
                <span class="dot">
                  <button type="button" (click)="openModalL1()" class="btn btn-default btn-circle btn-xl "><i
                      class="fa fa-history "></i></button>
                  <label class="carousel-label"> Modal L1</label>

                </span>
              </div>
               <div class="col-md-1" *ngIf="val === 'label 1'">
                <span class="dot">
                  <button type="button" (click)="openModalL1()" class="btn btn-default btn-circle btn-xl "><i
                      class="fa fa-history "></i></button>
                  <label class="carousel-label"> Modal L1</label>

                </span>
              </div>
               <div class="col-md-1">
                <span class="dot">
                  <button type="button" (click)="openModal()" class="btn btn-default btn-circle btn-xl "><i
                      class="fa fa-history "></i></button>
                  <label class="carousel-label"> Modal</label>

                </span>
              </div>
               <div class="col-md-1">
                <span class="dot">
                  <button type="button" (click)="openModal()" class="btn btn-default btn-circle btn-xl "><i
                      class="fa fa-history "></i></button>
                  <label class="carousel-label"> Modal</label>

                </span>
              </div>
            </div>

Answer №1

Consider developing a structural directive in Angular specifically for carousels. Carousels serve as a great example for implementing such directives. There is ample information available online, one useful resource can be found at the following link:

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

Storing a component in browser storage using JavaScript and Angular

I am currently working on developing an Angular application that allows users to "favorite" a business card and store it in local memory. I am facing challenges with actually storing the clicked element in the browser's local memory. Furthermore, I f ...

Switch the icon in Angular 2 while using ngFor loop

One issue I am facing with my angular2 project is that the icon does not appear when the page loads, but only after clicking. The array being used is called "keys". <ion-grid class="dueD-line" *ngFor="let line of keys; let i=index"> <div style= ...

Converting a data type into a CSS format

Currently, I am in the process of creating a table and would like to implement a 4-color scheme randomly selected from a pool of 10 schemes. Below is my CSS/PHP code: <?php header('Content-type: text/css'); // 0 grey $color00 = '#95 ...

How do I ensure that my font size completely fills the space in a justified layout using CSS?

Is there a way to style my text to match the appearance in the image shown using CSS? ...

Naming axes in Chart.js is a simple process that can easily be implemented

Greetings to all, I'm currently working on creating bar charts using chartjs...everything is going smoothly except for one thing - I am struggling to find a clean way to name my axes without resorting to CSS tricks like absolute positioning. Take a ...

Sending a specific object and its corresponding key as parameters to a reusable component in Angular: T[K]

I am currently working on developing a generic component in Angular and Typescript version 4.4.4. The goal is to create a component where I can set both an object (obj) and specific keys (properties). Here's a simplified version of my text component: ...

A guide on converting your current Angular app into a "fully strict" application – follow these steps!

I started developing an Angular Application back in Angular 4 and now it has been upgraded to Angular 12. However, during the initial development phase, the strict mode was not enabled. Now that the application is stable and live in production, I am lookin ...

Issue with the scope causing global variable not to update when button is pressed

I am facing an issue with a declared variable and jQuery code that is supposed to store a form's value as the value of that variable when a button is clicked, and then execute a function. var verb = ""; $( "#submit" ).click(function() { verb = $(& ...

Retrieving the data from a Material UI Slider control

I'm encountering an issue with retrieving the value property I assigned to a component. event.target.value is returning undefined. How can I successfully access the value of the component? My goal is for handlePlayersChange() to be able to handle dyn ...

What is the most efficient way to access a cell within an HTML table using jQuery or the Document Object Model (

I have an unchangeable HTML table styled with CSS. My goal is to extract the value from the first column for filtering purposes. I've been struggling to locate a suitable jQuery or DOM function to accomplish this task. Unable to find a way to access ...

Integrating fresh components into a JSON structure

I've been attempting to insert a new element into my JSON, but I'm struggling to do it correctly. I've tried numerous approaches and am unsure of what might be causing the issue. INITIAL JSON INPUT { "UnitID":"1148", "UNIT":"202B", "Sp ...

The file parameter in the upload is consistently undefined in tsoa-swagger

Having trouble with Tsoa nodejs File upload Followed the tsoa documentation for writing the method, but the output variable is consistently undefined This is my current method @Post('/uploadNewExporterTemplate') public async uploadNewExpo ...

Tips for Removing Padding in Material UI Container Component

I'm currently working on creating a hero banner using the material-ui framework and I've encountered an issue. Here's what I have so far: https://i.stack.imgur.com/UXTDY.png However, I'm facing an irritating problem with left and rig ...

warning: issue detected with the password value in jquery

Why is the following script generating an incorrect JavaScript alert message? <script type="text/javascript> $('#cpassword').change(function() { var pass=$('#password').val(); alert(pass); var cpass=$(& ...

Sorting through a list of strings by checking for a specific character within each string

After spending years dabbling in VBA, I am now delving into Typescript. I currently have an array of binary strings Each string represents a binary number My goal is to filter the array and extract all strings that contain '1' at position X I ...

Navigate to the following input field upon a keyup event occurring within the table

I have a table that contains multiple input fields in a single row within a td element. I am trying to implement functionality that will automatically shift focus to the next input field when any number is entered. The code works perfectly without the tabl ...

Struggling with implementing jquery Ajax and a php script to fetch information from a mysql database

I'm encountering issues with my current web app project in displaying a simple jpg image based on the selected radio button using jQuery AJAX along with a PHP script to interact with MySQL. Below is my ajax.js file: $('#selection').change( ...

Using NgRx to observe state changes in a service instead of relying on an Effect

Is it possible for a service to monitor state changes and make HTTP calls based on the state value without being triggered by an effect (NgRx)? In other words, can a service react to a portion of the store and eliminate the need for an effect to be involve ...

Maintaining the placement of dialogue boxes within the screenplay

I am facing an issue with displaying dialog boxes within a form. When I assign a div inside the form to a dialog, it gets moved to the bottom of the script and is no longer contained within the form element. As a result, I am unable to submit the values. ...

Using a Class Decorator in Typescript to Enhance Static Methods across all Classes

Imagine having a class filled with numerous static methods. The objective is to encapsulate each static method within a function. The specific aim is to handle async errors by applying .catch to every static method in the following manner: // Within user-r ...