Angular: Array in the template re-renders even if its length remains unchanged

Below is the template of a parent component:

<ng-container *ngFor="let set of timeSet; index as i">
    <time-shift-input *ngIf="enabled"
        [ngClass]="{ 
            'mini-times' : miniTimes, 
            'field field-last': !miniTimes,
            'field-central': !canAddSet,
            'field-central--long': (canAddSet || canDeleteSet) && !miniTimes }"
        [startHour]="set.startHour" 
        [endHour]="set.endHour"
        [endsNextDay]="set.endsNextDay" 
        [canAddSet]="canAddSet()"
        [canDeleteSet]="canDeleteSet(i)"
        [required]="true"
        (onAddSet)="onAddSet(i)"
        (onDeleteSet)="onDeleteSet(i)"
        (onChange)="onShiftTimes($event, i)"></time-shift-input>
</ng-container>

Below is the code that updates the timeSet array after triggering the onChange event:

public onShiftTimes( set: TimeSchedule | Array<TimeSchedule>, ind?: number ): void {
    if ( ind !== undefined ) {
        this.timeSet[ind] = <TimeSchedule>set;
    } else {
        this.timeSet = <Array<TimeSchedule>>set;
    }
    this.timeChanged.emit({
        data: this.timeSet,
        di: this.dayIndex
    });
}

Every time the onShiftTimes method is called, the child component <time-shift-input> gets re-rendered, even if the length of the array remains the same.

This negatively impacts user experience by disrupting focus and other elements. Initially, it was assumed that pushing or updating an index of an existing array would not change the object reference, preventing the ngFor loop from being triggered. However, surprisingly, ngOnInit in <time-shift-input> is still being called every time after onShiftTimes...

Do you have any suggestions to avoid this unwanted re-rendering?

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

What is the best way to fetch data before a component is rendered on the screen?

I am facing an issue with fetching data from a local server in Node. When I try to render the component, the array 'users' from the state appears to be empty, resulting in no users being displayed on the screen as intended. What's strange is ...

"Exploring the power of Nextjs Server-Side Generation with 10 million

I am working on a Next.js application that utilizes an API to fetch 10 million posts. I am considering using the SSG method for this purpose, but I am unsure if it is the standard approach. Additionally, I may need to add new posts dynamically in the fut ...

implementing firestore onsnapshotListner feature with pagination

I have a web application that needs real-time updates on a large collection of documents. However, due to the size of the collection, retrieving data without applying a limit is not feasible and inefficient. Therefore, it is crucial to implement a query li ...

JavaScript multi-click navigation menu

I'm relatively new to JavaScript and I've been struggling with using multiple onClick attributes. While I have some code that works, I feel like there might be a simpler and cleaner solution to my problem. What I'm trying to achieve is a na ...

Escape key does not close the modal dialogue box

I’ve customized the codrops slide & push menu (http://tympanus.net/codrops/2013/04/17/slide-and-push-menus/) to create an overlay on a webpage. Although it functions as intended, I’m struggling to implement a way to close it by pressing the escape ...

Is there a way to incorporate text at the end of a row in HTML?

I have a photo and some text on my website. The photo is displayed on the left side, while the text appears nicely on the right side. Now, I am looking to include an additional block of text below the existing text. How can I accomplish this? What steps ...

Not all divs are triggering the hover event as expected

I am facing an issue while creating a webpage with overlapping background and content divs. The hover event works properly on the div with the class "content," but not on the div with the class "background." There is no interference with the event in the J ...

Dual Networked Socket.IO Connection

I have set up a node.js server with an angular.js frontent and I am facing a problem with Socket.IO connections. The issue arises when double Socket.IO connections open, causing my page to hang. var self = this; self.app = express(); self.http = http.Ser ...

What is the process for removing an item from a JSON file using an HTTP DELETE request in a Node.js environment?

Essentially, I have a JSON file containing user and group data and I need to delete a specific group from it. Below is a snippet of the JSON file named authdata.json: [{ "name": "Allan", "role": ["Group Admin", "Super Admin"], "group": ["Cool- ...

Execute a PHP function using JavaScript/jQuery with AJAX requests

Hello everyone, I am reaching out for assistance with AJAX as I am still quite new to it. Despite the abundance of examples available, I find it challenging to grasp the concept. Specifically, I need help with my validation of a contact form using JavaScri ...

Do the items appear on screen only once you start typing in AngularJS?

Most things are working well except for a couple of issues Code var app = angular.module("MyApp", []); app.filter('offset', function() { return function(input, start) { start = parseInt(start, 10); return input.slice(start); }; } ...

How can I display several custom markers that are constantly updating on a Google map with MySQL and PHP?

Currently, I am using the following code to generate markers on a Google map by retrieving data from a database. However, the issue I am facing is that it only generates one marker instead of all the markers stored in the database. & ...

Need help accessing data from an API using Axios.post and passing an ID?

Can someone help me with passing the ID of each item using Axios.Post in order to display its data on a single page? The image below in my Postman shows how I need to send the ID along with the request. Additionally, I have the first two URL requests for t ...

Contrast in functionality between a pair of variables within a controller

Could you please clarify the distinction between two variables a1 and a2: app.controller("someCtrl",function(){ this.a1=somevalue; var a2=somevalue; }); Also, can you explain the lifespan of variable a2? ...

Encountering difficulty when trying to set custom headers in an Ionic GET request

Attempting to retrieve data from the backend by making a GET request, but encountering a failure. Initially, no error message is displayed, however, eventually an error with a "0" status code appears in the browser console. GET http://localhost:3001/api/p ...

Animating objects in ThreeJS to traverse multiple positions smoothly with linear interpolation (lerp)

I am exploring ways to animate a sphere's movement along a predefined sequence of vertices. I have successfully managed to animate the sphere from one point to another using the code below: function animate() { requestAnimationFrame(animate) spher ...

Is it possible to utilize [(ngModel)] in all components when including FormsModule in the app.module.ts file?

Is it possible to utilize [(ngModel)] in every component after importing FormsModule in app.module.ts? In app.module.ts import { FormsModule } from '@angular/forms'; Implementing in another component In view.component.html input type="text" ...

Fill in input field based on choice from the drop-down menu - JavaScript

I am facing an issue where I cannot add text inside the text box based on the dropdown selection. For example, if I select option2 from the dropdown, the textbox should be populated with option2. (function() { 'use strict'; setInterva ...

Is there a way to install @types that are compatible with an outdated version of TypeScript?

I am currently working on a project that relies on packages such as @types/express and @types/body-parser. The problem is, the recent updates to these .d.ts files have introduced generic defaults, which now require TypeScript 2.3 or higher. Unfortunately, ...

Tips for implementing multi-language URL routing in a Node.js application

I am seeking guidance on how to handle routing for multi-language URLs in Node.js, Currently, I have the following routes set up where each language generates specific routes as shown below. However, with more than 5 languages, efficiency is becoming a co ...