【发布时间】:2019-03-29 07:26:09
【问题描述】:
Taking this example from the doc:
Stream<List<Hero>> heroes;
// ···
void ngOnInit() async {
heroes = _searchTerms.stream
.transform(debounce(Duration(milliseconds: 300)))
.distinct()
.transform(switchMap((term) => term.isEmpty
? Stream<List<Hero>>.fromIterable([<Hero>[]])
: _heroSearchService.search(term).asStream()))
.handleError((e) {
print(e); // for demo purposes only
});
}
假设我想在ngOnInit()“触发”stream。
经过一些测试,我发现这可以通过调用void search(String term) => _searchTerms.add(term); 来完成就在此之后:
await Future.delayed(Duration(milliseconds: 1));
似乎ngOnInit() 内部的_searchTerms 调用不是等待。
谁能解释为什么会这样,或者我做错了什么?
【问题讨论】:
标签: dart angular-dart dart-html