title: How to prevent ngAfterViewInit() to get called before ngOninit completes execution
body: <p>I have used  angular materials for sorting a a table in angular 7 . So what is happening I am calling  rest service from <code>ngOnInit()</code> method . Then in ngAfterViewInit I have am wrting the below code for sorting.</p>
  
  <pre><code>ngAfterViewInit() {  
      this.dataSource.sort = this.sort;
    }
  </code></pre>
  
  <p>But what is happening is it is not waiting for the rest service to complete the execution and <code>ngAfterViewInit</code> is called before <code>ngOnInit</code> completes exceution.</p>
  
  <p>For the above reason Sorting is not happening in Webpage where I am displaying the table.</p>