@NickACE
react redux

Как сделать айди Observable?

Имееться компонент:
export class CharacterDetailsComponent implements OnInit {
  id$: string | null = '';
  characterDetail$!: Observable<CharacterData | undefined>;   

  constructor(
    private router: ActivatedRoute,
    private store$: Store
  ) {} 

  ngOnInit(): void {
    this.id$ = this.router.snapshot.paramMap.get('id'); 
    this.getCharacterDetail();
    this.characterDetail$ = this.store$.select(charDetailsSelector);
  }

  getCharacterDetail() { 
    if (!this.id$) {
      return;
    }
    this.store$.dispatch(getCharDetailsData({id: this.id$ }));
  }
}


Его экшн:
export const getCharDetailsData = createAction(
    '[Character Details Page] Load Details',
    props<{ id: string | null; }>()
  );


Вопрос, как правильно сделать id$: Observable что бы не было ошибок с типами?
  • Вопрос задан
  • 76 просмотров
Пригласить эксперта
Ответы на вопрос 1
Xuxicheta
@Xuxicheta Куратор тега Angular
инженер
export class CharacterDetailsComponent implements OnInit {
  readonly id$ = this.route.paramMap.pipe(map(paramMap => paramMap.get('id'));
  ....


Все
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы