javascript - 点击角度的下一个内容
问题描述
如何在点击时显示以下内容?
我有一个内容列表显示到 20 点,然后单击我想显示其余内容
我为此创建了 nextMovieList 方法
import { Component, OnInit } from '@angular/core';
import { MoviesService, Movie } from './shared/services/movies.services';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'app-entretien';
moviesList: Movie[];
moviesSelected: Movie[];
currentPage: number = 0;
constructor(private moviesService: MoviesService) {
}
ngOnInit() {
this.moviesService.getList(1, 20).subscribe(data => {
this.moviesList = data.content;
console.log(this.moviesList);
});
}
nextMoviesList() {
if (this.currentPage > this.moviesList.length) {
this.currentPage++
}
}
}
电影服务.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
export interface Movie {
attributes: {
actors: string; // acteurs
description: string; // synopsis
director: string; // réalisateur
duration: string; // durée en minute
title: string; // titre
year: string; // année de sortie
};
thumbnails: { // jaquettes
large: string;
medium: string;
small: string;
tiny: string;
xlarge: string;
};
}
export interface ApiReturn<T> {
code: number;
content: T[];
count: number;
description: string;
details: string;
limit: number;
page: number;
sort: string;
}
export interface ApiParams extends HttpParams {
_page: number;
_limit: number;
}
@Injectable({
providedIn: 'root'
})
export class MoviesService {
constructor(private http: HttpClient) {
}
getList(page: number, limit: number): Observable<any> {
return this.http.get('https://api-test.cnx-network.com/api/fuuze/content',
{ params: {
page: page + '',
limit: limit + '',
category: 'movies',
sort: 'order'
}
});
}
}
不明白如何实现页码接口 ApiParams 我不想显示特定数量的内容而是所有的内容
解决方案
演示您的 this.moviesList.length 是 20 那么为什么要与 paginate 进行比较?您也从 api 发送总计数,然后您可以从该计数创建总分页。在演示中创建一个参数,totalPage
然后在第一次调用 ngOnInit
this.totalPage=parseInt((data.total/20).toString());
data.total%20>0 ? this.totalPage++ : this.totalPage;
然后在你的函数中使用它作为比较
nextMoviesList() {
if(this.totalPage==this.currentPage){return;}
this.currentPage++
this.moviesService.getList(this.currentPage+1, 20).subscribe(data => {
this.moviesList = data.content;
});
}
如果您的服务与 paginate 一起使用,那么在您的nextMoviesList
函数调用服务中使用新的页面索引
推荐阅读
- r - 从 md 文件创建小插图,而不是 Rmd
- javascript - 如何使 SSL Websocket 与 Django 通道一起工作
- python - Seaborn 错误:找不到“高度”,它去哪儿了?
- javascript - 具有异步加载选项卡内容的 Angular 选项卡组。内容必须是另一个组件
- python - Python,WebScraping天气值
- java - googleCast getMediaInfo() 每次返回空值
- c++ - Ncurses - 在初始化我的窗口之前等待按钮按下的空白窗口
- angular-material - Mat 图标浮动在输入的右侧,并且不以键入的文本为中心
- selenium - microsoft edge 和 safari 浏览器中未识别元素
- push-notification - 如何为 Google Assistant 增加 10 次/天的推送通知限制