angular - 在 subject.next 之后,角度 observable 不加载服务
问题描述
我有一个输入文本,它在我的数据库中搜索并返回一个列表来填写我的 ng-for。如果为空,则显示所有记录。通过模态我插入一条新记录并想更新我的列表,但是当发送空时,observable 不会触发。
零件
private exameIdSubject = new Subject<string>();
anexoExames$ = this.exameIdSubject.pipe(
startWith(''),
liveSearch(search => this.apiExames.getAnexoExame(search))
);
searchExame(search: string) {
this.exameIdSubject.next(search);
}
onSubmit(){
if(this.exameForm.valid){
this.apiExames.addAnexoExame(this.exameForm.value)
.subscribe((exame:any)=>{
this.exameForm.reset();
this.searchExame('')
})
}
}
模式保存onSubmit并发出空值以更新列表,因为该值已被使用,它什么也不做。
运营商 LiveSearch https://medium.com/javascript-everyday/a-live-search-example-angular-and-react-solutions-bd42a4d5dd7e
更新
html
<div class="search-results mb-4">
<div class="input-group">
<input type="search" (input)="searchExame($event.target.value)" placeholder="Busca...">
</div>
</div>
<div *ngIf="anexoExames$ | async as vanexos; else indicator">
...
<tr *ngFor="let anexo of vanexos; let i=index">
...