【发布时间】:2019-04-07 16:17:31
【问题描述】:
我知道这是完全错误的......但是我找不到一个例子来实现它
search = '';
ngOnInit() {
this.countries$ = this.areasService.getCountries(this.search); //HttpClient request
}
search(key) {
this.search = key;
this.countries$.next();
}
<ul>
<li *ngFor="let c of (countries$ | async)?.docs">{{c.name}}</li>
</ul>
【问题讨论】:
-
你想完成什么?
-
我有一个国家列表和一个按名称搜索的输入
-
所以您想在每次搜索更改时调用获取国家/地区功能?
-
是的.....我认为 this.countries$.next();是正确的......但下一个不是函数是错误
-
Next 是一个供观察者使用的函数,如果你愿意的话,你可以做一个 switchmap 并在里面创建一个你调用 next 的主题,但我认为这基本上是下面给出的答案。
标签: angular observable angular-httpclient angular-pipe angular-observable