RxAngular Integration
interface HeroesComponentState {
heroes: Hero[];
}
const initHeroesComponentState: Partial<HeroesComponentState> = {
heroes: []
};
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css'],
providers: [RxState] // <--- This binds RxState to the lifetime of the component
})
export class HeroesComponent {
heroes: Hero[];
readonly heroes$: Observable<Hero[]> = this.state.select('heroes');
constructor(
store: Store,
private state: RxState<HeroesComponentState>
) {
const stateHeroes$ = store.select(getHeroes);
this.state.set(initHeroesComponentState);
this.state.connect('heroes', stateHeroes$); // <--- Here we connect NGXS with RxAngular
}
}Last updated

