Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 7e49c78

Browse files
devversionThomasBurleson
authored andcommitted
docs(virtual-repeat): extend common issues section (#9760)
* Add information about a common issue where developers were expecting the VirtualRepeat to detect changes outside of another scope. (#9711) * Added entry to common issues where developers were confused, whether the directives will be compiled / linked multiple times or not (#8638) Closes #8638. References #9711
1 parent a445b76 commit 7e49c78

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/components/virtualRepeat/virtual-repeater.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ angular.module('material.components.virtualRepeat', [
2626
*
2727
* ### Common Issues
2828
*
29-
* > When having one-time bindings inside of the view template, the VirtualRepeat will not properly
30-
* > update the bindings for new items, since the view will be recycled.
29+
* - When having one-time bindings inside of the view template, the VirtualRepeat will not properly
30+
* update the bindings for new items, since the view will be recycled.
31+
*
32+
* - Directives inside of a VirtualRepeat will be only compiled (linked) once, because those
33+
* are will be recycled items and used for other items.
34+
* The VirtualRepeat just updates the scope bindings.
35+
*
3136
*
3237
* ### Notes
3338
*
@@ -417,10 +422,44 @@ VirtualRepeatContainerController.prototype.handleScroll_ = function() {
417422
* `md-virtual-repeat` specifies an element to repeat using virtual scrolling.
418423
*
419424
* Virtual repeat is a limited substitute for ng-repeat that renders only
420-
* enough dom nodes to fill the container and recycling them as the user scrolls.
425+
* enough DOM nodes to fill the container and recycling them as the user scrolls.
426+
*
421427
* Arrays, but not objects are supported for iteration.
422428
* Track by, as alias, and (key, value) syntax are not supported.
423429
*
430+
* ### On-Demand Async Item Loading
431+
*
432+
* When using the `md-on-demand` attribute and loading some asynchronous data, the `getItemAtIndex` function will
433+
* mostly return nothing.
434+
*
435+
* <hljs lang="js">
436+
* DynamicItems.prototype.getItemAtIndex = function(index) {
437+
* if (this.pages[index]) {
438+
* return this.pages[index];
439+
* } else {
440+
* // This is an asynchronous action and does not return any value.
441+
* this.loadPage(index);
442+
* }
443+
* };
444+
* </hljs>
445+
*
446+
* This means that the VirtualRepeat will not have any value for the given index.<br/>
447+
* After the data loading completed, the user expects the VirtualRepeat to recognize the change.
448+
*
449+
* To make sure that the VirtualRepeat properly detects any change, you need to run the operation
450+
* in another digest.
451+
*
452+
* <hljs lang="js">
453+
* DynamicItems.prototype.loadPage = function(index) {
454+
* var self = this;
455+
*
456+
* // Trigger a new digest by using $timeout
457+
* $timeout(function() {
458+
* self.pages[index] = Data;
459+
* });
460+
* };
461+
* </hljs>
462+
*
424463
* > <b>Note:</b> Please also review the
425464
* <a ng-href="api/directive/mdVirtualRepeatContainer">VirtualRepeatContainer</a> documentation
426465
* for more information.

0 commit comments

Comments
 (0)