Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set a default value as an observable #158

Closed
ianjamieson opened this issue Aug 1, 2019 · 2 comments
Closed

How to set a default value as an observable #158

ianjamieson opened this issue Aug 1, 2019 · 2 comments

Comments

@ianjamieson
Copy link

I have ngrx-forms set up as per the documentation and can of course set an initial value like this:

export const initialState: FormGroupState<TermsFormState> = createFormGroupState<TermsFormState>(FORM_ID, {
  terms: 'Initial value'
});

However, the initial value is currently an observable, what is the best way to assign this value as the initial value? I was thinking using soemthing like this:

    this.formState$ = this.store.pipe(
      select(fromForms.getTermsForm),
      withLatestFrom(fromDefaults.getDefaults),
      map(([formState, defaults]) => {
        if (formState.isUntouched) {
          formState.controls.terms.setValue(defaults.terms);
        }
        return formState;
      })
    );

But it seems a little clunky just to set default values and also isUntouched always returns true

@ianjamieson ianjamieson changed the title How to set a default value How to set a default value as an observable Aug 1, 2019
@ianjamieson
Copy link
Author

Might be useful:

#45 (comment)

#112

@ianjamieson
Copy link
Author

Implemented a variation of the methods above, setting default state with a new action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant