Issue with updating @input within ngFor loop's binding circuit

I am dealing with a component that has two binded inputs, which are a large array and two markers indicating positions within the array.

This is how the component looks:

export class listSequence  { 
@Input() info: Data;
@Input() position: Markers;
..
...}

Here is what happens in the View:

I iterate through the bound data using @input, and utilize the markers (position.start and position.end) to only select specific elements from the array (note that these markers can change at any point).

<g *ngFor="#p of info.data  | slice:position.start:position.stop+1 ; let i = index ">..</g>

Sometimes, when one of the markers changes while looping through the info.data, the results become inconsistent.

In certain cases, one or two iterations occur after the marker change (either position.start or position.stop).

Upon updating component.start, the iterations should range from i:0 to i:14

https://i.sstatic.net/ap7co.jpg

Answer №1

Check out this plunker demo

Within the app.ts file, I am loading a large array where you'll notice it ends with elements "X", "Y", and "Z".

By dragging the navigator, you can navigate through the array displayed in the red section below. Occasionally, when dragging the left side of the navigator towards the right, some elements may not appear in their correct positions as indicated by the "X", "Y", and "Z" at the end.

In addition, you may observe inconsistencies in the iterator within the console log.

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

When attempting to instantiate a new file handler with the "new" keyword, the error "filehandler is not a constructor" is

Encountering the issue of "filehandler is not a constructor" when trying to use "new filehandler", but it does not work as a static class. USAGE: demos.filehandler.mjs file: import { default as filehandler } from "../index.js"; const FileHandl ...

Is there a way to conceal 'private' methods using JSDoc TypeScript declarations?

If we consider a scenario where there is a JavaScript class /** * @element my-element */ export class MyElement extends HTMLElement { publicMethod() {} /** @private */ privateMethod() {} } customElements.define('my-element', MyElement) ...

Saving user information in a MongoDB database with Node.js using a POST request

Currently, I am in the process of developing a web application using the MEAN stack along with Angular 6. One of the key functionalities is the ability to submit data into MongoDB via a form. Below is the function responsible for saving the extruded value ...

Utilizing Angular 2 directives with just JavaScript, is there a way to access the current element?

I am currently working in Angular 2 using Javascript. Within a directive, I find myself needing to access the current element to make changes to the DOM. It's worth noting that I can't use the commonly used hashtag trick (#element) because ther ...

Dynamic row insertion in Angular Material table during sorting操作

I utilized Angular material to create a table which looks like this: <mat-table #table [dataSource]="dataSource" matSort> <ng-container *ngFor="let item of displayedColumns; let i = index" cdkColumnDef="{{getColumnName(i)|Formater:'clean&apo ...

"How to automatically populate an input field with a value when the page loads in an

I need assistance with setting the input value to 1 when the page is loaded, but for some reason, it remains empty. Can someone help me troubleshoot this issue? <tr *ngFor="let item of cartItems; let i=index"> <td class="cart_pr ...

Creating a Mock ErrorHandler in Angular to Handle Rethrown throwErrors (using jasmine)

When using Jasmine, I have implemented tests to handle error logic from a subscribed Observable. this.apiService .post({}) .pipe( take(1), catchError((e) => { return throwError(() => e); }) ) ...

AngularFirestoreCollection can be thought of as a reference to a collection within Firestore, which

Hey there, I need some help with the following code snippet. Data link service file private dbUser = '/users'; constructor(private firestore: AngularFirestore) { this.userCollection = firestore.collection(this.dbUser); } Now in my component fi ...

Creating a TypeScript generic record with specified keys

I need to validate in TypeScript whether an object contains the specified keys (from SingleShopColumns or MultishopColumns) and has a validations property that is an array of strings. I am using Record and generics, but any simple method of representing t ...

Receiving numerous inputs from a single text box using Angular

I'm facing an issue when trying to accept input as an array in Angular. Below is my code snippet: <input type="number" [(ngModel)]="valuesArray"> <button (click)="PerformAction()" > find</button> va ...

Sending a parameter to a confidential npm module

I've developed a custom npm module that can be used in my applications by including this code snippet in the HTML: <app-header-name></app-header-name> Here is the TypeScript code inside the npm package: import { Component, OnInit } from & ...

registering a back button action in Ionic2 for multiple pages

Currently, I am in the process of developing my Ionic2 app and have encountered a dilemma regarding the functionality of registerBackButtonAction. On one page, let's call it pageA, I have implemented this function and everything is functioning as exp ...

The age-old debate: Ngxs or Behavior Subject, which one should you go

I'm embarking on creating an admin panel for a Payment gateway product using Angular's latest version, working with a multitude of microservices. With experience in NGXS state management, as well as subjects and behavior subjects, I'm undeci ...

Ways to ascertain whether a user has successfully logged in

Just diving into Angular testing and decided to test out the checkLogin function within my application. import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import {AuthenticationService} from &qu ...

Angular 2 ngFor generates a collection of rows and columns forming a single large column

It seems that ngfor is generating divs one by one, resulting in a poor design where they are stacked on top of each other. I would like to achieve a layout like this: [1] [2] [3] [4] [5] [6] However, the current outcome looks like this: [ 1 ] [ 2 ] [ 3 ...

Issue: Trying to emit before Angular Webpack plugin has been initialized (Error: Emit attempted before Angular Webpack plugin initialization)

Currently, I am working on a project in Angular 15 where I am migrating code from Angular version 5. Despite fixing all the errors, I'm facing one particular issue. Here are the details of my current Angular version: Angular CLI: 15.2.10 Node: 18.18. ...

Using Angular and RxJS to trigger an email once all values have been emitted successfully

saveData$ is an observable that emits multiple values. I am looking to optimize the email sending process by only sending one email once all values have been successfully emitted. Currently, an email is sent for each individual value that is emitted, whi ...

Limiting the defaultValue of a select to one of the values of its options in TypeScript: A guide

Is there a way to configure the Select component's properties so that the defaultValue is limited to one of the predefined options values ("au" | "nz" in this scenario)? const countryOptions = [ { value: "au", l ...

Understanding Typescript in Next.js components: Deciphering the purpose behind each segment

Consider the following function: type User = { id: string, name: string } interface Props { user: User; } export const getUserInfo: GetUserInfo<User> = async ({ user }: Props) => { const userData = await fetchUser(user.id); return ...

The guide to integrating the npm package 'mysql-import' into a node.js project with TypeScript

I'm currently facing an issue while trying to import a dump to a database using node.js and the npm module 'mysql-import'. Initially, I wrote the code in JavaScript and it worked flawlessly. However, when I attempted to modify it for TypeScr ...