我知道在Angular 4中可以使用别名管道输出,但这只对模板内的别名有用。
例如:
<div *ngIf="race | async as raceModel">
<h2>{{ raceModel.name }}</h2>
<small>{{ raceModel.date }}</small>
</div>
这里的raceModel不能在ngIf之外被引用。在我的情况下,我使用管道对集合进行排序和过滤,并希望获取过滤后返回集合的长度,以便更新我的NgbPagination。
我的代码:
<tr *ngFor="let cust of customers | filterBy: searchFilters: true | orderBy: order: reverse: true: start: end as collection">
<td>{{cust.id}}</td>
</tr>
</tbody>
</table>
<ngb-pagination *ngIf="customers"
(pageChange)="pageChange($event)"
[collectionSize]="collection.length"
[(page)]="page"
[(pageSize)]="pageSize"
[maxSize]="5"
[rotate]="true"
[ellipses]="true"
[boundaryLinks]="true">
</ngb-pagination>
如果可能的话,我不想把管道拖到视图模型中。有没有什么提示可以让我如何安全地从管道中获取变量以供稍后在视图中使用?