Tips for concealing boostrap spinners

Within the main component, I have an

@Input() alkatreszList$!: Observable<any[]>;
that gets passed into the child component input as @Input() item: any; using the item object:

<div class="container-fluid">
    <div class="row mb-3">
        <ng-container *ngFor="let item of filteredAlkatreszek; trackBy: trackByItemId">
            <div class="column">
                <app-carousel [item]="item"></app-carousel>
            </div>
        </ng-container>
    </div>
</div>

In the child component, there is a carousel within a container.

<ng-container *ngIf="img.trim() !== ''">
    <img [defaultImage]="'https://localhost:7094/images/placeholder.png'"
         [lazyLoad]="'https://localhost:7094/images/' + img" style="height: 250px"
          [debug]="true"
          (onStateChange)="lazyLoadSpinner(i, $event)"
          (click)="selectItem(item)"/>
          <div class="progress-container" [ngClass]="{ 'd-none': isItemLoaded(i) }">
              <div class="spinner-overlay"></div>
              <div class="spinner-container">
                  <div class="spinner-border text-light" role="status">
                    <span class="visually-hidden">Loading...</span>
                  </div>
              </div>
          </div>
      </ng-container> 

These variables are utilized in various functions:

activeIndexModal = 0;
activeIndexCarousel = 0;  
loadedCounts: number[] = [];

lazyLoadSpinner(index: number, event: StateChange) {
    if (!this.loadedCounts[index]) {
      this.loadedCounts[index] = 0;
    }
    
    switch (event.reason) {
        case 'start-loading':
            if (this.loadedCounts[index] === 0) {
                // Start loading for a new item
                this.loadedCounts[index] = -1;
            }
            break;

        case 'loading-succeeded':
            this.loadedCounts[index]++;
            if (this.loadedCounts[index] >= this.item.kepek.split(';').length) {
                this.loadedCounts[index] = 0;
            }
            break;
    }
}

isItemLoaded(index: number): boolean {
    console.log("isItemLoaded() called");
    return this.loadedCounts[index] === 0;
} 

The issue with the spinners persists where, irrespective of whether OnPush or Default change detection strategy is used in the child component, interaction with carousels or other elements on the site is necessary for the spinners to disappear after isItemLoaded() returns true. Suggestions for a better design approach or identifying issues in the code would be appreciated.

Here are the CSS rules and remaining template code for the child component:

.carousel-item {
    height: 400px !important;
    width: 100% !important;
    margin-bottom: var(--bs-gutter) !important;
}
  
.carousel-item.reactive img {
    object-fit: cover !important;
    height: 100% !important;
    width: 100% !important;
    transition: transform 0.2s;
}

/* Additional CSS rules continue ... */

Answer №1

I was able to resolve this issue by communicating a state change back to the parent component. In the child component, I used

@Output() loadingSucceeded: EventEmitter<StateChange> = new EventEmitter<StateChange>();
to emit the proper state when lazy loading is detected.

Within the parent component, I included

<app-carousel [item]="item" (loadingSucceeded)="triggerChangeDetection()"></app-carousel>
and

triggerChangeDetection() {
    this.cdr.detectChanges();
  }

This was accomplished with the assistance of the ChangeDetectorRef class.

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

Include previous input as a "phantom" thumbnail to the slider element of type "range"

https://i.stack.imgur.com/JnuCN.png Using a tutorial from w3schools, I have customized a regular range slider. The objective is to send a new value command to an external MQTT-based home automation system and display the previous value as a ghost-thumb in ...

Footer positioned correctly with relative DIV

I find myself in a state of complete confusion. Coding is not exactly my forte, so I suspect I have made a significant error somewhere that is causing the following issue: My goal is to create a sticky footer. The footer does indeed stick to the bottom of ...

Typescript: Understanding the question mark usage on arrays

In this example, I have the basic structure of my code: let myArray: (Array<any> | null); if (cnd) { myArray = []; myArray?.push(elt); // Curious about this line myArray[0].key = value; // Questioning this line } else { myArray = null; } Wh ...

unable to locate text within tag a using javascript

I developed JavaScript code to search for tags within an accordion. function tagSearch(){ let keyword = document.getElementById('find').value.toUpperCase(); let items = document.querySelectorAll('.accordion'); let links = document ...

Issue: AuthInterceptor Provider Not Found

I've been attempting to set up an http interceptor with the new HttpClient in Angular 4.3, but I'm continuously encountering this error message: ERROR Error: Uncaught (in promise): Error: No provider for AuthInterceptor! In my app.module.ts f ...

Having difficulty sending the [ctrl][p] keys to a page that is not using Angular framework

Working with protractor version 5.1.2, Angular 5, and typescript 2.4.2 When attempting to trigger a 'print' function using the shortcut keys '[ctrl][p]' in protractor on a non-angular page, I encountered an issue. Within my protractor ...

Position the title of the Bootstrap selectpicker field to the right

I utilized Creative Tim's Material Dashboard Pro to create a select field. My goal is to align both the select field and its options to the right. Currently, I have only been successful in aligning the options while the title and selected option rema ...

Adjust hover effects based on true conditions

Currently working on a web app using HTML, CSS, JavaScript, and AngularJS. Progress so far includes a clickable box that triggers a javascript function to display more boxes upon click using ng-click. <div ng-click="!(clickEnabled)||myFunction(app)" cl ...

Display exclusively the provided value

Can someone please help me with printing in PDF style and displaying only the inputted value without showing the textbox or dropdown? Check out this image for reference I would like to achieve something similar, how can I do that? Any assistance would be ...

Setting up the Font Awesome Pro version in Angular using the Font-Awesome package

The process of installing the pro version of Angular Font-awesome began with setting up my registry using these commands: npm config set "@fortawesome:registry" https://npm.fontawesome.com/ && \ npm config set "//npm.fontawesome.com/:_authTo ...

Develop a versatile currency symbol mixin that can be used in various small text formats

I am currently working on a website where I need to display prices in multiple locations. To achieve this, I have created a sass mixin that is designed to add the desired currency symbol before the price with a smaller font-size. Below are examples of how ...

Identify the currently active subitem within the item-active class in a PHP carousel slider

I am working on creating an image carousel slider with 4 items and 4 slides each. These images will act as radio buttons, and I want to highlight the slide corresponding to the selected radio button. So, when the carousel loads, the selected slide should b ...

Can you use `keyof` to create a template literal type?

Defined a form schema type example: type FormSchema = { username: string; settings: { theme: string; language: string } } Now, trying to define the Form Input type like this: type FormInput = { id: keyof FormSchema | `${keyof FormSchema}.${string}` } Enc ...

The compatibility issue between Bootstrap and Angular 2 is causing some challenges

Hey there, I recently enrolled in an Angular 2 course on udemy and everything was running smoothly until I encountered an issue while trying to install bootstrap. I followed the installation steps diligently, but whenever I attempt to add any bootstrap el ...

Aligning a Facebook share button to the center of a webpage

On my webpage, I have the following section: <div style="align:center"> <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js#appId=217585988283772&amp;xfbml=1"></script> <fb:like hre ...

Attempting to consistently place an element at the bottom of my div container

I am attempting to align my <span class="fechar_fancy">Back/span> at the bottom of my div, regardless of the height of my content. I want this element to always be positioned at the bottom. Therefore, I tried using position:absolute and bottom:0 ...

Angular: a versatile button that can perform various actions

My item has the capability to undergo various actions such as edit, delete, copy, upgrade, and more. Depending on the status of the item, only one action can be executed at a time. Therefore, I aim to develop a button component in Angular that will be dis ...

The use of URL embedded parameters in @angular/http

Currently, I am utilizing a backend system that accepts search query parameters in both the ?-notation and the url-embedded format. I understand that I can use tools like URLSearchParams/RequestOptionsArgs to send requests to . However, I am curious about ...

Tips for inserting a pin into a designated location on an image map

Within my angular application, I have implemented an image map using the HTML usemap feature. Here is the code snippet: <img src="../../assets/floor2.jpg" usemap="#floor2Map"> <map name="floor2Map"> <area shape="pol ...

Tips for adjusting the height and border of Bootstrap tabs

I'm facing an issue with the modal and nav-tabs I created. There are a couple of problems that need to be addressed. Firstly, the tabs have excessive height and I've tried adjusting it using CSS height property, but it's not working as e ...