I have a basic form control which subscribed 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');
}
}
When I call setValue the observer doesn't get any notification. It seems that the async pipe doesn't work. If I wrap the setValue in setTimeout, it's working. Why it behaves like that?
I also tried to add shareReplay() which also doesn't work.