# Cannot ViewChild ion-infinite-scroll, cannot call its method then

**URL:** <https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743>\
**Category:** ionic-v3\
**Created:** [November 29, 2017, 7:19am UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743 "2017-11-29T07:19:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidvalen95](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/davidvalen95/32/115381_2.png) [@davidvalen95](https://forum.ionicframework.com/u/davidvalen95)\
**Post date:** [November 29, 2017, 7:19am UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/1 "2017-11-29T07:19:48Z")

</div>

so i need to enable the ion-infinite-scroll from other function rather than its output emited (ionInfinite)=doInfinite($event)

my html for infinite scroll, notice that we pass $event instead of #infiniteScroll, its wierd, we usually pass the instance of #

```html
<ion-infinite-scroll #infiniteScroll (ionInfinite)="doInfinite($event)">
      <ion-infinite-scroll-content>LLoading</ion-infinite-scroll-content>
    </ion-infinite-scroll>

```

this is the doInfitinet output emit callback

```typescript
// ionInfinite output emited
// this will disable infinitescroll if pagination is completed
  public doInfinite(infinite:InfiniteScroll){
    if(this.visitationData.length >= (this.visitationData[0].maxpage)) {
      infinite.enable(false);

    }else{
      infinite.enable(true);

      this.getVisitation(this.visitationData.length+1).then(data=>{
        if(data){
          infinite.complete();

        }
      });
    }

  }

```

this is the other function, **Notice the comment in the code, that line generate error**

```typescript

  @ViewChild('infiniteScroll') public infiniteScroll:InfiniteScroll;
  public filterChanged() {
    console.log(this.filter);
    this.visitationData = [];
    // this.infiniteScroll.enable(true) <-- this calling method is from ViewChild, this line generate error
    this.getVisitation();
  }

```

the error generated says, which mean its not a Infinite scroll

> TypeError: this.infiniteScroll.enable is not a function

please help me

---

<div class="post-metadata">

**Author:** ![davidvalen95](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/davidvalen95/32/115381_2.png) [@davidvalen95](https://forum.ionicframework.com/u/davidvalen95)\
**Post date:** [November 29, 2017, 8:28am UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/2 "2017-11-29T08:28:37Z")

</div>

Ok i have solution, but it doesnt answer my curiosity of why cannot do ViewChild infinite scroll

solution: Bind enabled to variable

```auto

    <ion-infinite-scroll [enabled]="this.isInfiniteEnable" (ionInfinite)="doInfinite($event)">
      <ion-infinite-scroll-content>LLoading</ion-infinite-scroll-content>
    </ion-infinite-scroll>

```

---

<div class="post-metadata">

**Author:** ![MrFloppy](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@MrFloppy](https://forum.ionicframework.com/u/MrFloppy)\
**Post date:** [March 7, 2018, 2:37pm UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/3 "2018-03-07T14:37:28Z")

</div>

I just got the same issue. I think because the view child doesn’t give you a infinity scroll element but an ElementRef to the DOM element. So you don’t have the methods of that ionic element.  
Probably you can access this somehow via the child element. But I was lazy too and used the way you did it too 😉

---

<div class="post-metadata">

**Author:** ![raschidjfr](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raschidjfr/32/137849_2.png) [@raschidjfr](https://forum.ionicframework.com/u/raschidjfr)\
**Post date:** [April 2, 2018, 9:56pm UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/4 "2018-04-02T21:56:04Z")

</div>

Hey I got the solution to that! use the `read` parameter in `ViewChild` like this:

```auto
@ViewChild('infiniteScroll', {read: InfiniteScroll}) public infiniteScroll:InfiniteScroll;

```

That way your telling `ViewChild` to fetch the `InfiniteScroll` component instead of the DOM element.

---

<div class="post-metadata">

**Author:** ![durairaj](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@durairaj](https://forum.ionicframework.com/u/durairaj)\
**Post date:** [September 25, 2019, 12:49pm UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/5 "2019-09-25T12:49:36Z")

</div>

thanks man its worked for me

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:01pm UTC](https://forum.ionicframework.com/t/cannot-viewchild-ion-infinite-scroll-cannot-call-its-method-then/113743/6 "2021-07-19T22:01:55Z")

</div>

Closed on July 19, 2021, 10:01pm UTC


