【发布时间】:2018-11-04 19:57:45
【问题描述】:
我有一个订阅了 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');
}
}
当我调用 setValue 时,观察者没有收到任何通知。似乎异步管道不起作用。如果我将 setValue 包装在 setTimeout 中,它就可以工作。为什么会这样?
我也尝试添加 shareReplay() 也不起作用。
【问题讨论】:
标签: angular typescript rxjs