title: Ionic 3 - Runtime Error Cannot read property 'scrollToTop' of null
body: <p>I'm working on a project in Ionic 3. There are different menus. On selecting a menu I'm just publishing an event and changing the value of array on the page. Everything is working fine, but when the data of the page changes the scroll bar remains at the previous position. I want that everytime I select an item from menu the the page should be scrolled to top.</p>
  
  <p>For this I'm using this-</p>
  
  <p>The event is being published on selecting a menu item. The code is writtent at app.component.ts</p>
  
  <pre><code>onSelectCourse(slug){
      const loading = this.loadingCtrl.create({
          content: 'Loading Articles'
      });
      loading.present();
      if(slug == 'all'){
          this.postsProvider.listPosts(1)
          .subscribe(data =&gt; {
              this.events.publish('posts:listed', data);
              loading.dismiss();
              this.menuCtrl.close();
          });
      }
      else{
          this.postsProvider.listPostsByCategory(slug, 1)
          .subscribe(data =&gt; {
              this.events.publish('posts:listed', data);
              loading.dismiss();
              this.menuCtrl.close();
          });
      }
  }
  </code></pre>
  
  <p>Subscribing the event at HomePage (home.ts)-</p>
  
  <pre><code>export class HomePage {
      posts: any = [];
      pages: number;
      page: number;
      category: string;
      @ViewChild(Content) content: Content;
      constructor(
                  private events: Events,
                  private postsProvider: PostsProvider,
                  private changeRef:ChangeDetectorRef) {
          this.events.subscribe('posts:listed', (data) =&gt; {
              this.posts = data.posts;
              this.pages = data.pages;
              this.page = 1;
              this.category = data.category;
              this.changeRef &amp;&amp; this.changeRef.detectChanges();
              this.content.scrollToTop();
          });
      }
  }
  </code></pre>
  
  <p>But on selecting an item, I'm getting this error</p>
  
  <p><a href="https://i.stack.imgur.com/fTyia.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTyia.png" alt="enter image description here"></a></p>