Gathering detailed insights and metrics for ng2-vs-for
Gathering detailed insights and metrics for ng2-vs-for
Gathering detailed insights and metrics for ng2-vs-for
Gathering detailed insights and metrics for ng2-vs-for
npm install ng2-vs-for
Typescript
Module System
Node Version
NPM Version
71.3
Supply Chain
98.2
Quality
75.6
Maintenance
50
Vulnerability
99.3
License
TypeScript (86.16%)
HTML (13.84%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
42 Stars
38 Commits
25 Forks
5 Watchers
1 Branches
4 Contributors
Updated on Nov 16, 2022
Latest Version
1.1.1
Package Id
ng2-vs-for@1.1.1
Size
13.89 kB
NPM Version
3.7.3
Node Version
5.8.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Use verion 1.1.x with angular2.0.0-rc
Use version 1.0.11 with angular2.0.0-beta
This is a port of https://github.com/kamilkp/angular-vs-repeat for Angular2
The name stands for Virtual Scroll For. It manipulates the collection you want to ngFor
over in a way that only elements that are actually visible for the user are rendered in the DOM. So if you repeat over a thousand items only a few of them are rendered in the DOM, because the user can't see the rest anyway. And it takes time for the browser to render so many elements, which also might have some event listeners/bindings etc. So you should see a considerable boost in performance.
npm install ng2-vs-for
Basic usage: all items shall have the same height
1<div *vsFor="items; #_items = vsCollection"> 2 <div *ngFor="#item of _items"> 3 <!-- item html here --> 4 </div> 5</div>
Items have varoius sizes but they are known up front (calculatable based on their properties)
1import {VsFor} from 'ng2-vs-for'; 2import {Component} from 'angular2/core'; 3 4@Component({ 5 selector: 'some-component', 6 directives: [VsFor], 7 template: ` 8 <div *vsFor="items; size:getSize; #_items = vsCollection"> 9 <div *ngFor="#item of _items"> 10 <!-- item html here --> 11 </div> 12 </div> 13 14 `, 15 inputs: ['items'] 16}) 17 18export class SomeComponent { 19 items: any; 20 getSize(item, index) { 21 let size; 22 // ... do some calculations here 23 return size; 24 } 25}
The getSize
could either be a number (or string castable to number) or a function on your component. If it's a function it will be called for each item in the original collection with two arguments: item
(the item in the collection), and index
(the index in the original collection). This function shall return a number - the height in pixels of the item.
The vsFor
directive is a structural directive and it exposes two local variables:
vsCollection
- the sliced collection that should be assigned to a local variable and be used in ngFor
vsStartIndex
- the index of the first element that is actually rendered (see last example at the bottom of the readme)Other parameters that you can pass to the vsFor
directive:
offsetBefore
(defaults to 0)offsetAfter
(defaults to 0)excess
(defaults to 2)autoresize
(set to true recalculates on window resize)horizontal
(hooks to scrolling horizontally and the optional size
parameter calculates widths instead of heights)tagName
(defaults to div
) - should be the same type as the tag name of the element you put the ngFor
directive onscrollParent
(defaults to direct parent element) - a selector of the closest element that is the scrollable container for the repeated items. You can set window
as a scroll parent in case the main window scrollbar should be used.Example with some more parameters:
1<table> 2 <tbody *vsFor="items; size:getSize; tagName:'tr'; autoresize:true; scrollParent:'window'; excess:3; #_items = vsCollection; #_startIndex = vsStartIndex"> 3 <tr *ngFor="#item of _items; #i = index"> 4 {{ i + _startIndex }} <!-- the actual index in the original collection --> 5 </tr> 6 </tbody> 7</table>
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More