Я пытаюсь отобразить список пользователей, получающих значение ввода и использующих его в качестве параметра метода get()
. Я получаю возврат get()
и использую push для вставки его в объект, затем пытаюсь отобразить этот объект в шаблоне.
Я хотел:
- Поиск пользователя.
- Показать этого пользователя.
- Поиск другого пользователя.
- Показать другого пользователя вместе с первым.
Но шаблон показывает ошибку:
{ "_isScalar": false, "source": { "_isScalar": false, "source": { "_isScalar": false, "source": { "_isScalar": true, "value": { "url": "http://localhost:3000/users", "body": null, "reportProgress": false, "withCredentials": false, "responseType": "json", "method": "GET", "headers": { "normalizedNames": {}, "lazyUpdate": null, "headers": {} }, "params": { "updates": [ { "param": "user", "value": "Teste", "op": "s" } ], "cloneFrom": null, "encoder": {}, "map": {} }, "urlWithParams": "http://localhost:3000/users?user=Teste" } }, "operator": { "concurrent": 1 } }, "operator": {} }, "operator": {} }
Мой компонент.ts:
import { HttpClient, HttpParams } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.scss']
})
export class InfoComponent implements OnInit {
public buscar: string;
users: any;
private readonly url = 'http://localhost:3000/users';
select: any;
usuario = [
{
user: ''
}
];
constructor(private http: HttpClient) { }
ngOnInit() {
this.users = this.http.get(this.url);
}
getDados(event) {
if (event.keyCode === 13) {
const params = new HttpParams().set('user', this.buscar);
this.select = this.http.get(this.url, { params });
}
this.usuario.push({
user: this.select
});
}
}
Мой component.html:
<igx-input-group type="search" class="search">
<igx-prefix>
<igx-icon>search</igx-icon>
</igx-prefix>
<input #search igxInput placeholder="Buscar" (keydown)="getDados($event)" [(ngModel)]="buscar">
<igx-suffix *ngIf="search.value.length > 0" (click)="searchContact = null">
<igx-icon>clear</igx-icon>
</igx-suffix>
</igx-input-group>
<div class="list-sample">
<igx-list>
<igx-list-item isHeader="true">Users</igx-list-item>
<igx-list-item #item *ngFor="let users of users | async">
<div class="item-container">
<div class="contact">
<div class="contact__info">
<span class="id">{{users.id}} </span>
<span class="user">{{users.user}}</span>
</div>
</div>
</div>
</igx-list-item>
</igx-list>
</div>
<p *ngFor="let usuario of usuario">{{ usuario.user | json }}</p>
Буду признателен за любую добрую душу, готовую помочь.