Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.