Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
angular-virtual-scroll
Advanced tools
Source for the sf.virtualScroll module for AngularJS
Intended as a replacement for ng-repeat
for large collections of data and
contains different solutions to the problem.
The module was originally developed as a proof of concept but has matured into
a useable component. It isn't the ideal solution to the performance issues of
large ng-repeat
instances, but it does work as a drop-in replacement (with
some caveats).
It started because I needed to display log messages and I didn't want to use
paging. There were some excellent alternatives including some wrappers of
jQuery grids, but nothing was using the ng-repeat
pattern. I wrote a couple
of articles explaining myself as I went along:
There should be an online demo here: http://demo.stackfull.com/virtual-scroll/
Whether you build the component, copy the raw source or use bower (see below),
the end result should be included in your page and the module sf.virtualScroll
included as a dependency:
angular.module('myModule', ['sf.virtualScroll']);
Then use the directive sf-virtual-repeat
just as you would use ng-repeat
.
<div class="viewport">
<div>
<table>
<tbody>
<tr sf-virtual-repeat="line in book.lines"><th>{{$index}}: <td>{{line}}
</table>
</div>
</div>
<div class="viewport real">
<ul>
<li ng-repeat="thing in simpleList">{{thing}}</li>
</ul>
</div>
If you want to expose the scroll postion (to simulate an atEnd
event for
example), use ng-model
and you have access to the scroll properties.
Check out the examples in the demo folder for all the details.
First up, the obligatory warning: virtual scrolling is usually the wrong approach. If you want to display really large lists, your users will probably not thank you for it: filtering can be a more friendly way to tame the data. Or if you have performance problems with angular bindings, one of the "bind-once" implementation may make more sense.
Tables are problematic. It is possible to use sf-virtual-repeat
in a <tr>
to create table rows, but you have to be very careful about your CSS.
The element having the sf-virtual-repeat
needs to be contained within an
element suitable for use as a viewport. This suitability is the main difficulty
as the viewport must contain a single element (and no text) and this contained
element must be explicitly sizable. So a table
will need 2 parent div
s for
example.
The collection must be an array (not an object) and the array must not change identity - that is, the value on the scope must remain the same and you should push, pop, splice etc. rather than re-assigning to the scope variable. This is a limitiation that might be removed in future versions, but for now it's a consequence of watching the collection lightly.
Grunt is used as the build tool, so you will need
node and npm installed. Since v0.4,
grunt has 2 parts: the heavy lifting package grunt
and the shell command
grunt-cli
. If you haven't already installed grunt-cli
globally, do so now
with:
sudo npm install -g grunt-cli
To run the simple demo, install the npm dependencies for the build tools and go:
npm install
grunt demo
You can now view the demo at http://localhost:8000/
Build with grunt dist
and choose a file from the dist
directory.
For use with bower, there is a separate repo containing just the built artifacts here: angular-virtual-scroll-bower. You can add the component to your project with:
bower install angular-virtual-scroll
Or by adding a line to your component.json
file.
If you are using grunt
for your build, consider using a plugin like
bowerful.
All comments to paul@stackfull.com
First "dagnamit" fix.
First sight of daylight.
FAQs
angular-virtual-scroll ======================
The npm package angular-virtual-scroll receives a total of 111 weekly downloads. As such, angular-virtual-scroll popularity was classified as not popular.
We found that angular-virtual-scroll demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.