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 {
@Select(getHeroes) stateHeroes$: Observable<Hero[]>; // <--- normal @Select use from NGXS
heroes: Hero[];
readonly heroes$: Observable<Hero[]> = this.state.select('heroes');
constructor(private state: RxState<HeroesComponentState>) {
this.state.set(initHeroesComponentState);
this.state.connect('heroes', this.stateHeroes$); // <--- Here we connect NGXS with RxAngular
}
}Last updated

