Skip to content

Commit

Permalink
feat(infinite-scroll): it can be enabled/disabled from a ng input
Browse files Browse the repository at this point in the history
references #8380
  • Loading branch information
manucorporat committed Oct 9, 2016
1 parent 88da70c commit 8e2bbba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demos/src/infinite-scroll/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ApiDemoApp {
infiniteScroll.complete();

if (this.items.length > 90) {
infiniteScroll.enable(false);
infiniteScroll.setEnable(false);
}
});
}
Expand Down
15 changes: 14 additions & 1 deletion src/components/infinite-scroll/infinite-scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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.setEnable(shouldEnable);
}

/**
* @output {event} The expression to call when the scroll reaches
* the threshold distance. From within your infinite handler,
Expand Down Expand Up @@ -212,11 +222,14 @@ export class InfiniteScroll {
* enabled or not. Setting to `false` will remove scroll event listeners
* and hide the display.
*/
enable(shouldEnable: boolean) {
setEnable(shouldEnable: boolean) {
this.state = (shouldEnable ? STATE_ENABLED : STATE_DISABLED);
this._setListeners(shouldEnable);
}

/**
* @private
*/
_setListeners(shouldListen: boolean) {
if (this._init) {
if (shouldListen) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/infinite-scroll/test/basic/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class E2EPage1 {

if (this.items.length > 90) {
this.enabled = false;
infiniteScroll.enable(this.enabled);
infiniteScroll.setEnable(this.enabled);
}
});
}
Expand All @@ -40,7 +40,7 @@ export class E2EPage1 {

toggleInfiniteScroll() {
this.enabled = !this.enabled;
this.infiniteScroll.enable(this.enabled);
this.infiniteScroll.setEnable(this.enabled);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class E2EPage {
infiniteScroll.complete();

if (this.items.length > 90) {
infiniteScroll.enable(false);
infiniteScroll.setEnable(false);
}
});
}
Expand Down

0 comments on commit 8e2bbba

Please sign in to comment.