angular - 用于视图的 Angular HttpClient 分页
问题描述
我有一个服务,方法如下:
public getAlerts(page: number, opts?: AlertRequestOptionsInterface): Observable<AlertInterface[]> {
const path = `/alerts/list`;
const body = { page: page, ...opts };
return this._http.post<AlertInterface[]>(path, body, { headers: headers })
.catch(() => Observable.of(undefined));
}
我将它绑定到我的视图中,如下所示:
@Component({
selector: 'page-alerts',
templateUrl: 'alerts.html',
})
export class AlertsPage {
public alerts: Observable<AlertInterface[]>;
public subscription: Subscription;
public loading: boolean = true;
constructor(private _alerts: AlertsService) { }
public ionViewDidEnter() {
this.alerts = this._alerts.getAlerts(1);
this.subscription = this.alerts.subscribe(() => {
this.loading = false;
});
}
public ionViewWillLeave() {
this.subscription.unsubscribe();
}
}
如果我想分页并将下一页 API 调用附加到我的页面上,我Observable<AlertInterface[]>
将如何在视图方面执行此操作?
解决方案
推荐阅读
- browser - 我可以创建一个浏览器扩展来阻止下载特定文件类型并将用户转发到链接吗?
- java - 如何使用 IntelliJ 编译 Java 项目并在终端中运行 (NoClassDefFoundError)
- sql - 尝试将 varchar 转换为十进制的 SQL 错误
- java - 为什么我的程序会抛出这个 JNI 错误?
- html - 网页不接受从 vba 发送的文本
- r - 尝试从 URL 中抓取表格但无法抓取整行
- java - 下载大结果
- javascript - 从 ajax php 脚本取回数据
- github - 将一些项目从 Azure Devops 同步到 Github 或其他解决方案?
- mysql - Django - Mysql Database is not created in Docker