0
我有一個對象數組,我想根據大小這是對象的屬性進行排序。對象由{name,size}組成。我想根據大小對元素進行排序。OrderBy Pipe不適用於agular 4中的對象數組嗎?
服務:
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};
});
});
}
組件:
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 –
角犯規什麼從盒子中提供'orderBy'管道.. –