我问这个是因为我开始学习一些基本的角度课程,并且我正在使用一些过滤器,在我使用 ValueChanges 输入时将请求发送到 firebase:
这是用于搜索的输入:
<input
type="search"
placeholder="Teclee un proveedor..."
[formControl]="campoBusqueda"
/>
Run Code Online (Sandbox Code Playgroud)
这是我必须使用的代码ngOnInit():
this.campoBusqueda = new FormControl();
this.campoBusqueda.valueChanges.subscribe(term => {
this.busqueda = term;
this.cargando = true;
if (this.busqueda.length !== 0) {
this.proveedoresService
.getProveedoresSearch(this.busqueda)
.subscribe(proveedores => {
this.proveedores = [];
// tslint:disable-next-line: forin
for (const id$ in proveedores) {
const p = proveedores[id$];
p.id$ = id$;
this.proveedores.push(proveedores[id$]);
}
if (this.proveedores.length < 1 && this.busqueda.length >= 1) {
this.noresultados = true;
this.proveedoresService
.getProveedores()
.subscribe( proveedores => {
this.proveedores = []; …Run Code Online (Sandbox Code Playgroud)