L
L
lssssssssssl2021-09-29 17:30:48
Angular
lssssssssssl, 2021-09-29 17:30:48

How to bind form control state to ngrx selectors?

titleFormControl: new FormControl('Сюда хочу передать значение селектора и когда состояние редакса меняется, чтобы значение инпута этой форм котролы тоже менялось', [
      Validators.required,
    ]),


I found a crutch in filling the value of the input through the form control in the effect:
courseInfoSuccess$ = createEffect(() =>
    this.dataPersistence.fetch(CourseInfoActions.CourseInfoSuccess, {
      run: (action, state) => {

        this.courseInfoService.courseInfoForm.controls.idFormControl.setValue((action as any).payload.id)
        this.courseInfoService.courseInfoForm.controls.titleFormControl.setValue((action as any).payload.title)
        this.courseInfoService.courseInfoForm.controls.subTitleFormControl.setValue((action as any).payload.subTitle)
        this.courseInfoService.courseInfoForm.controls.descriptionFormControl.setValue((action as any).payload.description)
      },
      onError: (action, error) => this.errorHandler(action, error)
    })
  );

But it looks scary, and for this the form group needs to be taken out to the service. And selectors are not used at all in this case

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question