How can I populate a form with data from the store if setValue and patchValue methods are not working?
export class MyComponent implements OnInit, OnDestroy {
public newsletterToEdit$: Observable<NewNewsletter> =
this.store.selectNewsletterToEdit();
public form = this.fb.group({
title: ['', Validators.required],
subtitle: ['', Validators.required],
message: ['', Validators.required],
users: [''],
groups: [''],
searchedUsers: [''],
searchedGroups: [''],
allowReplies: [false, Validators.required],
replyFrom: ['NONE'],
});
ngOnInit(): void {
// this.newMessageForm.controls['title'].setValue('test title'); -> this works, it populates control with the string
this.newsletterToEdit$.pipe(
tap((newsletter) => {
console.log('newsletter to edit: ', newsletter);
// this.newMessageForm.patchValue(newsletter) -> another try
this.form.setValue({
title: newsletter.title,
allowReplies: null,
groups: newsletter.sentToGroupCode[0],
message: newsletter.message,
replyFrom: 'NONE',
searchedGroups: '1',
searchedUsers: '2',
subtitle: newsletter.subtitle,
users: '3',
});
})
);
}
}
I have confirmed that there is data in the store, but for some reason, the console log is never showing up which indicates that pipe(tap()) are not being called