feat(infinite-scroll): it can be enabled/disabled from a ng input (#8385)

closes #8380
This commit is contained in:
Manu Mtz.-Almeida
2016-10-12 19:25:26 +02:00
committed by Brandy Carney
parent 4964944056
commit fd5cdf0597
3 changed files with 14 additions and 3 deletions

View File

@ -135,6 +135,16 @@ export class InfiniteScroll {
} }
} }
/**
* @input {boolean} Whether or not the infinite scroll should be
* enabled or not. Setting to `false` will remove scroll event listeners
* and hide the display.
*/
@Input()
set enabled(shouldEnable: boolean) {
this.enable(shouldEnable);
}
/** /**
* @output {event} The expression to call when the scroll reaches * @output {event} The expression to call when the scroll reaches
* the threshold distance. From within your infinite handler, * the threshold distance. From within your infinite handler,
@ -221,6 +231,9 @@ export class InfiniteScroll {
this._setListeners(shouldEnable); this._setListeners(shouldEnable);
} }
/**
* @private
*/
_setListeners(shouldListen: boolean) { _setListeners(shouldListen: boolean) {
if (this._init) { if (this._init) {
if (shouldListen) { if (shouldListen) {

View File

@ -29,7 +29,6 @@ export class E2EPage1 {
if (this.items.length > 90) { if (this.items.length > 90) {
this.enabled = false; this.enabled = false;
infiniteScroll.enable(this.enabled);
} }
}); });
} }
@ -40,7 +39,6 @@ export class E2EPage1 {
toggleInfiniteScroll() { toggleInfiniteScroll() {
this.enabled = !this.enabled; this.enabled = !this.enabled;
this.infiniteScroll.enable(this.enabled);
} }
} }

View File

@ -23,7 +23,7 @@
</button> </button>
</ion-list> </ion-list>
<ion-infinite-scroll (ionInfinite)="doInfinite($event)" threshold="100px"> <ion-infinite-scroll (ionInfinite)="doInfinite($event)" [enabled]="enabled" threshold="100px">
<ion-infinite-scroll-content <ion-infinite-scroll-content
loadingSpinner="bubbles" loadingSpinner="bubbles"
loadingText="Loading more data..."> loadingText="Loading more data...">