Angular 2 how can i make my variable wait async for values?
<p>I have this error :</p>

<blockquote>
  <p>TypeError: Cannot read property 'length' of undefined at PaginationComponent.ngOnChanges (pagination.component.ts:38)</p>
</blockquote>

<p>This is my <code>PaginationComponent</code>:</p>

<pre><code>@Input() items = [];
@Input('page-size') pageSize;
@Output('page-changed') pageChanged = new EventEmitter();
pages: any[];
currentPage; 
public numberofpages = 10;
ngOnChanges(){
    this.currentPage = 1;
    var pagesCount = this.items.length / this.pageSize; 
    this.pages = [];
    for (var i = 1; i &lt;= pagesCount; i++)
        this.pages.push(i);
}
</code></pre>

<p>This how I am using it in another component <code>AboutUsComponent</code>:</p>

<pre><code>&lt;pagination [items]="posts" [page-size]="pageSize" (page-changed)="onPageChanged($event)"&gt;&lt;/pagination&gt;
</code></pre>

<p>And the posts are loaded in AboutUsComponent:</p>

<pre><code>private loadPosts(){
    this.postsLoading = true;
    this._aboutusService.getPosts().subscribe( 
        posts =&gt; {this.posts = posts;
                  this.pagedPosts = this.getPostsInPage(1)}, 
        null, 
        () =&gt; { this.postsLoading = false});
}
</code></pre>

<p>As I understand it happens because of <code>.subscribe()</code> async loading of posts and <code>@Input() items = [];</code> could be loaded before posts come.
How can I make it await or what over solution may you suggest?
Thank you.</p>