I am currently working with a basic form control that subscribes to the valueChanges observable.
@Component({
selector: 'my-app',
template: `
<input [formControl]="control" />
<div>{{ name$ | async | json }}</div>
`
})
export class AppComponent implements OnInit {
name$: Observable<string>;
control;
constructor(private builder: FormBuilder) {
this.control = this.builder.control('');
}
ngOnInit() {
this.name$ = this.control.valueChanges
.pipe(
map((name) => {
console.log('fired', name)
return name;
})
);
this.control.setValue('2');
}
}
However, I have encountered an issue where when I call setValue, the observer does not receive any notification. It appears that the async pipe is not functioning as expected. Strangely, if I wrap the setValue method in a setTimeout, it starts working correctly. Can anyone shed some light on why this behavior occurs?
In an attempt to solve this issue, I also tried using the shareReplay() method, but unfortunately, it did not resolve the problem either.