Created
June 16, 2019 10:10
-
-
Save imkrish/3efa9d20a582eddb79e839dbd57f7ac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppComponent implements OnInit, OnDestroy { | |
@Selector(CustomersState.SelectedCustomer) | |
private selectedCustomer$: Observable<Customer>; | |
@Selector(OrdersState.NewOrder) | |
private newOrder$: Observable<Order>; | |
private onComponentDestroy$: Subject<void>; | |
constructor() { | |
this.onComponentDestroy$ = new Subject(); | |
} | |
ngOnInit() { | |
this.selectedCustomer$ | |
.pipe(takeUntil(this.onComponentDestroy$)) | |
.subscribe(customer => { | |
// Do something | |
}); | |
this.newOrder$ | |
.pipe(takeUntil(this.onComponentDestroy$)) | |
.subscribe(order => { | |
// Do something | |
}); | |
} | |
ngOnDestroy() { | |
this.onComponentDestroy$.next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment