0
Ich habe ein Array von Objekten und ich möchte sie nach Größe sortieren, die ein Attribut des Objekts ist. Das Objekt besteht aus {Name, Größe} .Ich möchte die Elemente nach ihrer Größe sortieren.OrderBy Pipe funktioniert nicht auf Array von Objekten in agular 4?
Service:
search(term: string): Observable<Array<Object>> {
let apiURL = `${this.apiRoot}?search=${term}`;
return this.http.get(apiURL)
.map(res => {
return res.json().results.map(items => {
return {name: items.name, population: items.population};
});
});
}
Komponente:
ngOnInit() {
this.myshared.getSaveBtnStatus().subscribe(data => this.isSuccess = data);
this.searchField = new FormControl();
this.searchField.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.switchMap(term => this.myservice.search(term))
.subscribe(value => {
this.results = value;
console.log(this.results);
}
);
HTML:
<ul class="list-group">
<li class="list-group-item" *ngFor="let items of results">
{{items.name | orderBy : ['population'] }}
</li>
Angular2 + 'OrderByPipe' https://angular.io/guide/pipes#no-filter-pipe –
Angular tut nicht haben will Stellen Sie 'orderBy' Rohr aus der Box. –