cdk-virtual-scroll-viewport displays every single element in the list

I am currently utilizing cdk-virtual-scroll-viewport to display a List, but it seems to be rendering all the elements in a similar fashion as a traditional ngFor loop.

  <cdk-virtual-scroll-viewport itemSize="16">
    <div *cdkVirtualFor="let i of nums" style="color: aliceblue;">
        {{ i }}
    </div>
  </cdk-virtual-scroll-viewport>

Answer №1

Have you attempted adjusting the viewport height to control how many elements are displayed simultaneously?

To do this in the HTML, assign a class to the viewport element:

<cdk-virtual-scroll-viewport itemSize="16" class="custom-viewport">

In your CSS file:

.custom-viewport {
    height: 48px; /* Displaying 3 elements at once */
}

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

Can the NGXS store be shared between independent Angular (sub)projects?

Current Scenario: I am working on a micro-frontend setup consisting of a primary Angular application acting as the host, with multiple Angular libraries imported as modules that function as separate 'sub-apps'. Objective: My main aim is to estab ...

Time picker in Bootstrap - Ensuring end time is not earlier than start time validation

How to prevent users from selecting a past time for the end time in Bootstrap time picker with start time validation <html> <head> </head> <body> <link href="https://maxcdn.bootst ...

Maintain the initial worth even when making alterations

I've been working with Ag-grid and facing an issue. Initially, I load the original data into the grid using this.rowData. I have a function called addRow that successfully adds a row to the top of the existing rows. However, when the reset function ...

JEST: Troubleshooting why a test case within a function is not receiving input from the constructor

When writing test cases wrapped inside a class, I encountered an issue where the URL value was not being initialized due to dependencies in the beforeAll/beforeEach block. This resulted in the failure of the test case execution as the URL value was not acc ...

What is the best way to wait for a thread to finish executing before calling a function in Angular 5?

After starting a thread, I've encountered an issue where a function is being called before the thread has completed. What changes should I make to ensure the function is called after the thread completes? this._listService.getListById ...

Unlocking the Power of CheerioJS for Selecting Table Elements

I am struggling to figure out how to use CheerioJS to parse HTML table values and convert them into a JSON object. Despite my efforts, I have only been able to come up with a convoluted solution that doesn't quite work. My goal is to extract informa ...

Execute a function once the data has been displayed in the Angular2 template

When subscribing to a method that makes an API call, I handle the received data by assigning it to an object. Here is how I do it: this.serviceObj.getData() .subscribe( data => { this.DataObj = { ..... some content ..... } this.an ...

Navigating through diverse objects in Typescript

My challenge involves a state object and an update object that will merge with the state object. However, if the update value is null, it should be deleted instead of just combining them using {...a, ...b}. const obj = { other: new Date(), num: 5, ...

Yup will throw an error if both a minimum value is set and the field is also marked

I am attempting to validate my schema using yup: import * as yup from "yup"; let schema = yup.object().shape({ name: yup.string().min(5) }); const x = { name: "" }; // Check validity schema .validate(x, { abortEarly: false }) . ...

Difficulty modifying the background color of a bar graph in Chart.js within an Ionic 2 Angular2 environment

I've been working with Chart.js in an Ionic2 and Angular2 hybrid app to create a stacked bar graph. However, I'm facing an issue where I can't seem to change the background color or fill color of the bars in the graph. Despite trying out all ...

"Utilize the right-click paste feature in the

Currently, I am utilizing tinymce within my application and am interested in pasting copied content using context menu options. Upon reviewing the documentation, I was unable to locate any information on paste options. Could someone kindly provide me wit ...

"Attempting to verify a JSON Web Token using a promise that returns an object not compatible with the specified

Learning about Typescript has been quite a challenge for me, especially when it comes to using the correct syntax. I have implemented a promise to retrieve decoded content from jwt.verify - jsonwebtoken. It is functioning as intended and providing an obje ...

Omit modules from the ng-bootstrap package when working with Angular 2

Is it possible to import specific components from the ng-bootstrap module into Angular 2? Currently, I have a custom tabset created using an existing ng-bootstrap component. However, upon importing ng-bootstrap, I am encountering a module duplication erro ...

Understanding how to handle prop types in a React application using Typescript

My current task involves using the react-google-maps library to integrate Google Maps API into my project. The documentation specifies a certain way to set up the maps component: const GoogleMapComponent: React.ComponentClass<{}> = compose( with ...

Creating an array in Angular is done by using the syntax []

I encountered an error and I'm not sure how to fix it. Can someone assist me? The error message reads: "Type '{ animal:[{ id : 1,name: "Elephant"},{id : 2, name: "Horse"} []; }' is not assignable to type 'string[]'. Property & ...

What is the use of the typeof operator for arrays of objects in TypeScript?

How can I update the any with the shape of the options's object below? interface selectComponentProps { options: { label: string; value: string; }[]; } const SelectComponent: React.FC<selectComponentProps> = ({ options, }) => ...

Firebase Error: Page Not Found

I recently set up an Angular2 application and added Firebase using npm. I successfully imported it into my app.component.ts without any errors showing up in my text editor. The package.json file also indicates that Firebase is installed correctly. However ...

When attempting to run the npm install command, an error message stating that npm is not recognized as a

While in the midst of executing npm install on the package.json file for my Angular 10 project, I encountered the following error: 'npm' is not recognized as an internal or external command, operable program or batch file. I am confident that ...

Sending various values to several instances of Angular components

I recently developed a basic Angular component called custom-component, which includes an input parameter and a button that, when clicked, simply logs the parameter value to the console. Declaration of the Input Parameter: @Input() componentType: string; ...

Achieving Effective Integration with XML REST Response in Angular 2

I'm currently working on an exciting Angular2 project. The application makes requests to a WebService which returns XML responses. In my Service class that handles this WebService communication, I have the following method: callPost() { return t ...