Skip to content

Instantly share code, notes, and snippets.

@mikehaas763
Created October 19, 2016 18:10
Show Gist options
  • Save mikehaas763/f2fd2769aca9b6d51e45ff8f475dad9d to your computer and use it in GitHub Desktop.
Save mikehaas763/f2fd2769aca9b6d51e45ff8f475dad9d to your computer and use it in GitHub Desktop.
//In an onPush component a method called by constructor this code exists:
this.store.select('searchResultsGrid')
.map(results => results.visibleResultsCount)
.distinctUntilChanged()
.skip(1)
.subscribe(count => {
console.log('new count is ', count);
this.resultsCount = count;
this._cdRef.markForCheck();
})
//This is the binding on the components template:
//<span *ngIf="resultsCount !== 1" class="md-headline">{{resultsCount}} Results</span>
//<span *ngIf="resultsCount === 1" class="md-headline">{{resultsCount}} Result</span>
//the code inside of the subscription fires, but the view does not reflect the change until the next event triggers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment