Skip to content

Instantly share code, notes, and snippets.

@tzachbon
Created November 20, 2019 14:51
Show Gist options
  • Select an option

  • Save tzachbon/21a5cc6d5113a379a5a3686d255e6c63 to your computer and use it in GitHub Desktop.

Select an option

Save tzachbon/21a5cc6d5113a379a5a3686d255e6c63 to your computer and use it in GitHub Desktop.
WithObservable
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ReRenderOnChange, SetChecker, WithObservable } from '@intelligo.ai/bonfire';
@ReRenderOnChange()
@Component({
selector: 'app-test',
styles: [
`
.container {
margin: 1rem;
color: white;
}
`
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div class="container">
<button (click)="initRandomNumber()">
<h1>{{ (changed$ | async).showChange ? (changed$ | async).changeText : 'Start' }}</h1>
</button>
</div>
`,
})
export class TestComponent implements OnInit {
@WithObservable() changed = {
showChange: false,
changeText: ''
}; changed$: BehaviorSubject<any>;
constructor(
private cd: ChangeDetectorRef
) { }
ngOnInit() {
}
initRandomNumber() {
setTimeout(() => {
this.changed.showChange = true;
this.changed.changeText = 'New text WOW!';
}, 2200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment