The entire DOM in Angular2+ flickers upon loading a component using ngFor

I am facing an issue where, after a user clicks on an item to add it to a list and then renders the list using ngFor, there is a flickering effect on the screen/DOM. The strange thing is that this flicker only happens after adding the first item; subsequent additions do not cause any flickering.

Below is the code for my ngFor loop:

<div
  *ngFor="let sel of selected"
    class="cw-selected-list-item"
 >
 <div class="cw-selected-name t4">{{ sel.id }}</div>
   <app-checkbox class="cw-selected-r-tick"></app-checkbox>
   <app-checkbox class="cw-selected-rw-tick"></app-checkbox>
 </div>

The flicker disappears when I comment out the app-checkbox components. Here's the code for the app-checkbox component:

TS

import { Component, OnInit, Input, Output, EventEmitter } from "@angular/core";
@Component({
 selector: "app-checkbox",
 templateUrl: "./checkbox.component.html",
 styleUrls: ["./checkbox.component.scss"],
})
export class CheckboxComponent implements OnInit {
 @Input() checked = false;
 @Output() checkChanged = new EventEmitter();

constructor() {}

ngOnInit(): void {}

toggleChecked() {
  this.checked = !this.checked;
  this.checkChanged.emit(this.checked);
 }
}

HTML

<div
 class="checkbox clickable"
 [ngClass]="{ 'checkbox-active': this.checked }"
 (click)="toggleChecked()"
>
<img
 class="checkbox-image"
 [ngStyle]="{ opacity: !this.checked ? 0 : 1 }"
 src="assets/buttons/tick.png"
/>

Any assistance in resolving this flickering issue would be greatly appreciated.

EDIT

Simply calling this function when the user clicks:

  selected = [];

  public addToSelected(item: Document) {
   this.selected.push(item);
  }

HTML

    <div
      *ngFor="let hit of hits"
       class="aisd-hit t4"
       [ngClass]="{ 'hit-disabled': this.isAlreadySelected(hit) }"
       (click)="
          this.isAlreadySelected(hit) ? undefined : this.addToSelected(hit)
        "
     >

Function to check if already selected:

  isAlreadySelected(doc: Document) {
   return this.selected.includes(doc);
  }

Answer №1

I finally figured it out!

The issue was caused by importing my fonts locally using .woff2 files, resulting in a complete DOM refresh whenever a new component was created after view initialization.

Sharing this solution in case it helps someone else

For example:

  url(/assets/fonts/opensans/mem8YaGs126MiZpBA-UFUZ0bbck.woff2)
  format("woff2");

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

Parsing temporary storage of database query results

My experience with OOP languages like C# and Java has been good, but I am relatively new to JavaScript/TypeScript. I find callback functions confusing, especially when using them with the BaaS ParseDB. For example, finding all playlists for a certain user ...

Using typescript in react to define conditional prop types

Currently, I am utilizing react-select as my select component with the multi prop. However, my goal is to have the onChange argument set as an array of options when the multi prop is true, and as OptionType when false. To achieve this, I am implementing di ...

Transfer highlighted checkboxes between two containers. Any deselected checkboxes in the second container should also be removed from the initial container

I have successfully populated the necessary checkboxes within a single div element. Furthermore, I have been able to save the selected checkboxes to an object. https://i.sstatic.net/Pn0pu.png I am interested in learning how to display this object (check ...

Are two JavaScript functions conflicting with each other?

Seeking assistance with integrating a Javascript/PHP/AJAX clock into my website to display various timezones (tutorial link: ) The clock implementation is functional, but it conflicts with an existing javascript stopwatch on the page, causing the clock no ...

Struggling to integrate Docker compatibility into an established NextJS project, encountering the frustrating "stat app/.next/standalone: file does not exist" message

I'm currently in the process of enhancing my existing NextJS + TypeScript project with Docker support and preparing to deploy it on Google Cloud Run. To achieve this, I've been referring to a helpful guide available at: https://github.com/vercel/ ...

Guide to setting up 2-factor authentication on GitHub using an AJAX request

My task is to query GitHub for all open pulls, but I'm new to this and don't have anyone to turn to for guidance. The only resources I've found so far are the documentation on . I came across a solution on that explains how to provide a us ...

Display every even number within the keys of objects that have values ending with an odd number

I need a way to print all even values that are paired with odd values in the object keys, but my code only works for arr1, arr3, and arr5. Can someone help me adjust the 'let oddArr' method (maybe using a loop) so that it will work for any array ...

Overlap of sub menus

Seeking assistance from a CSS expert for a challenge I am facing. I am currently working on a toggle menu for mobile view, and encountering issues with the submenu. Any list item placed below another one with children is not visible. Removing the parent l ...

How to retrieve a string in an Angular 6 http get request

Having trouble retrieving a string from my request. fetchData(id: string): string { let result: string = ''; this.dataService.getData(id).subscribe( response => { result = response.body.value; }, error => { cons ...

Choose an option using jQuery with the ability to navigate to the previous or next

I encountered a bug when I tried to click the next or previous button. Below is the HTML code snippet: $("#nextPage").click(function() { $('#pagination option:selected').next().attr('selected', 'selected'); console.log( ...

Node.js: Array remains undefined despite being logged on the console

My goal is to download a CSV file, read it line by line, and add the split lines (based on ',') to the tmparray. This code successfully prints all the elements in the array. var request = require('request'); var fs = require('fs&a ...

Manipulate a nested array in MongoDB with JavaScript array functions

Having trouble updating a field with mixed types in my mongoose schema. Although I acknowledge this may not be the ideal schema setup, there are specific reasons why it's structured this way. My goal is to perform array-like operations using JavaScrip ...

How can you display a personalized modal or error message using React context while incorporating dynamic content?

Can you please help me figure out how to display a custom modal or error message using react context with dynamic content? I attempted it like this: https://codesandbox.io/s/sleepy-wozniak-3be3j import React, { useState } from "react"; import ErrorConte ...

Creating an object with mapped properties from enumeration values using Typescript

I am trying to find a way to automatically create an object with values computed during compilation using enumeration values and pre-defined function calls. The basic concept is to associate certain arguments of a function with keys. For example, consider ...

Error in Discord Bot: discord.js showing TypeError when trying to read the length of an undefined property

I'm currently working on developing a Discord bot and using CodeLyon's Permissions V2 video as a guide for reference. There seems to be an issue in my message.js file which contains the following code: require('dotenv').config(); //cre ...

How can I fix the issue of clearInterval not functioning properly in an Electron JS application?

The clearInterval function is not working properly in this code. What can be done to fix this issue? var inter; ipcMain.on("start-stop",(err,data)=>{ console.log(data.data) function start(){ inter = setInterval(fu ...

Discovering the scroll position in Reactjs

Utilizing reactjs, I am aiming to manage scroll behavior through the use of a `click` event. To start, I populated a list of posts using `componentDidMount`. Next, upon clicking on each post in the list using the `click event`, it will reveal the post de ...

Stop HTML <dialog> from automatically closing using Vue

I'm working on a project where I need to use Vue to programmatically prevent an HTML dialog element from closing when the close event is triggered. Here's the code snippet I am currently using: import {ref} from 'vue'; const dialogTe ...

Tips for addressing the issue of mat-list-item not occupying the entire row's space

Hello everyone, I am currently trying to render an article.component.html within my article-list-component.html in a list format. When I use plain HTML, it renders correctly as shown in picture 1: Title - author - Date Here is the code for my article-list. ...

Is there a way to trigger a function in an AngularJS controller from a Backbone controller?

I've been working on an application that was originally developed using backbone and jQuery, but we had to incorporate new modules built with angular to meet client requirements. Routing in the application is handled by backbone route, and we have suc ...