angular实现list列表和翻页效果

server/2024/12/4 18:19:50/

说明:angular实现list列表和翻页效果
上一页 当前页面 下一页
效果图:
在这里插入图片描述

step1: E:\projectgood\ajnine\untitled4\src\app\car\car.component.css

.example-form-fields {display: flex;align-items: flex-start;
}mat-list-item{background: antiquewhite;
}

stp2: E:\projectgood\ajnine\untitled4\src\app\car\car.component.html

<button style="margin-top: 50px" mat-flat-button color="primary" (click)="inPassClick()">上一页</button>
<p>当前页数:{{this.onPage +1}}</p>
<button mat-flat-button color="primary" (click)="inNextClick()">下一页</button>
<button mat-flat-button color="primary" (click)="onNum()">当前数组</button><mat-nav-list><mat-list-item *ngFor="let user of users" (click)="onAddClick(user.id)"><span style="font-size: 20px;color: red;margin-right: 50px">{{ user.id }}</span><span>{{ user.name }}</span></mat-list-item>
</mat-nav-list>

step3:E:\projectgood\ajnine\untitled4\src\app\car\car.component.ts

import {Component, OnInit} from '@angular/core';
import {MatButton} from '@angular/material/button';
import {MatListItem, MatNavList} from '@angular/material/list';
import {NgForOf} from '@angular/common';@Component({selector: 'app-car',standalone: true,imports: [MatButton,MatListItem,MatNavList,NgForOf],templateUrl: './car.component.html',styleUrl: './car.component.css'
})
export class CarComponent implements OnInit {onPage: number = 0  //当前页数users: Details[] = []numLength = 3;  //最大页数 最小页数为0result: any = [];numPage = 3; /*每页显示条目数*/ngOnInit(): void {// let data = ['刘备','张飞','关羽','马超','诸葛亮','华雄','潘凤','赵云','孙权','曹操','吕布','董卓','貂蝉','孙尚香','周瑜','小乔',];for (let i = 0, len = userDatas.length; i < len; i += this.numPage) {this.result.push(userDatas.slice(i, i + this.numPage));}this.users = this.result[0]this.numLength = this.result.length - 1console.log(this.result);}inPassClick(): void {console.log('上一页')if (this.onPage > 0) {this.onPage--;}this.users = this.result[ this.onPage]}inNextClick(): void {console.log('下一页')if (this.onPage < this.numLength) {this.onPage++;}this.users = this.result[ this.onPage]}onNum(): void {console.log(this.onPage)console.log(this.result[this.onPage])}onAddClick(key: number): void {console.log(key)}}interface Details {id: number;name: string;avatar: string;details: string;isAdmin: boolean;isCool: boolean;
}const userDatas = [{id: 0,name: 'Lia Lugo',avatar: 'svg-11',details: 'I love cheese, especially airedale queso. Cheese and biscuits halloumi cauliflower cheese cottage ' +'cheese swiss boursin fondue caerphilly. Cow port-salut camembert de normandie macaroni cheese feta ' +'who moved my cheese babybel boursin. Red leicester roquefort boursin squirty cheese jarlsberg blue ' +'castello caerphilly chalk and cheese. Lancashire.',isAdmin: true,isCool: false},{id: 1,name: 'George Duke',avatar: 'svg-12',details: 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata ' +'corpora quaeritis. Summus brains sit, morbo vel maleficia? De apocalypsi gorger omero undead survivor ' +'dictum mauris.',isAdmin: false,isCool: true},{id: 2,name: 'Gener Delosreyes',avatar: 'svg-13',details: 'Raw denim pour-over readymade Etsy Pitchfork. Four dollar toast pickled locavore bitters McSweeney\'s ' +'blog. Try-hard art party Shoreditch selfies. Odd Future butcher VHS, disrupt pop-up Thundercats ' +'chillwave vinyl jean shorts taxidermy master cleanse letterpress Wes Anderson mustache Helvetica. ' +'Schlitz bicycle rights chillwave irony lumberhungry Kickstarter next level sriracha typewriter ' +'Intelligentsia, migas kogi heirloom tousled. Disrupt 3 wolf moon lomo four loko. Pug mlkshk fanny pack ' +'literally hoodie bespoke, put a bird on it Marfa messenger bag kogi VHS.',isAdmin: true,isCool: true},{id: 3,name: 'Lawrence Ray',avatar: 'svg-14',details: 'Scratch the furniture spit up on light gray carpet instead of adjacent linoleum so eat a plant, kill ' +'a hand pelt around the house and up and down stairs chasing phantoms run in circles, or claw drapes. ' +'Always hungry pelt around the house and up and down stairs chasing phantoms.',isAdmin: false,isCool: false},{id: 4,name: 'Ernesto Urbina',avatar: 'svg-10',details: 'Webtwo ipsum dolor sit amet, eskobo chumby doostang bebo. Bubbli greplin stypi prezi mzinga heroku ' +'wakoopa, shopify airbnb dogster dopplr gooru jumo, reddit plickers edmodo stypi zillow etsy.',isAdmin: false,isCool: true},{id: 5,name: 'Gani Ferrer',avatar: 'svg-16',details: 'Lebowski ipsum yeah? What do you think happens when you get rad? You turn in your library card? ' +'Get a new driver\'s license? Stop being awesome? Dolor sit amet, consectetur adipiscing elit praesent ' +'ac magna justo pellentesque ac lectus. You don\'t go out and make a living dressed like that in the ' +'middle of a weekday. Quis elit blandit fringilla a ut turpis praesent felis ligula, malesuada suscipit ' +'malesuada.',isAdmin: true,isCool: true},{id: 6,name: 'fans Ferrer',avatar: 'svg-17',details: 'Lebowski ipsum yeah? What do you think happens when you get rad? You turn in your library card? ' +'Get a new driver\'s license? Stop being awesome? Dolor sit amet, consectetur adipiscing elit praesent ' +'ac magna justo pellentesque ac lectus. You don\'t go out and make a living dressed like that in the ' +'middle of a weekday. Quis elit blandit fringilla a ut turpis praesent felis ligula, malesuada suscipit ' +'malesuada.',isAdmin: true,isCool: true}
];

end


http://www.ppmy.cn/server/140528.html

相关文章

力扣(leetcode)每日一题 3255 长度为 K 的子数组的能量值 II|滑动窗口

3255. Find the Power of K-Size Subarrays II 1.题干 You are given an array of integers nums of length n and a positive integer k. The power of an array is defined as: Its maximum element if all of its elements are consecutive and sorted in ascending ord…

【Python】轻松解析JSON与XML:Python标准库的json与xml模块

轻松解析JSON与XML&#xff1a;Python标准库的json与xml模块 在现代数据处理与交换中&#xff0c;JSON&#xff08;JavaScript Object Notation&#xff09;和XML&#xff08;eXtensible Markup Language&#xff09;是最常用的两种数据格式。它们广泛应用于API数据传输、配置…

【elkb】kibana后台删除索引

打开kibana后台 点击 Management ---> Index Management 找到要删除的所以点击 点击delete index 删除成功

opencv保姆级讲解——光学学符识别(OCR)(4)

光学字符识别 &#xff08;Optical Character Recognition, OCR&#xff09;是指对文本材料的图像文件进行分析识别处理&#xff0c;以获取文字和版本信息的过程。也就是说将图象中的文字进行识别&#xff0c;并返回文本形式的内容 以下是比较流行的开源的ORC识别库 Tessera…

高考:心态、时间、知识,多维度攻略让你脱颖而出

高考&#xff0c;宛如一场无声的激战&#xff0c;承载着无数莘莘学子的梦想与热望。在这激烈的竞争中&#xff0c;充分且周全的准备显得尤为关键。那么&#xff0c;高考备考究竟应从哪些方面入手&#xff1f;又有哪些行之有效的备考策略能为我们保驾护航呢&#xff1f; 一、高考…

八、Spring Boot集成Spring Security之前后分离认证最佳实现测试

文章目录 往期回顾&#xff1a;Spring Boot集成Spring Security专栏及各章节快捷入口前言一、正常流程测试1、登录接口测试2、业务接口测试3、登出接口测试 二、非正常流程测试1、输入错误用户名密码登录2、无请求头访问业务接口3、无效请求头访问业务接口4、登出时未携带有效请…

Vue 3 中Pinia状态管理库的使用方法总结

Pinia 是 Vue 3 的状态管理库&#xff0c;旨在替代 Vuex&#xff0c;提供更简洁和更灵活的 API。以下是如何在 Vue 3 项目中使用 Pinia 的详细步骤。 1. 安装 Pinia 首先&#xff0c;你需要在你的 Vue 3 项目中安装 Pinia。你可以使用 npm 或 yarn 进行安装&#xff1a; npm…

青少年编程与数学 02-003 Go语言网络编程 17课题、Go语言Cookie编程

青少年编程与数学 02-003 Go语言网络编程 17课题、Go语言Cookie编程 课题摘要:一、Cookie编程1. 发送Cookies2. 接收Cookies3. 删除Cookies4. Cookie的安全性5. 使用第三方库总结 二、应用场景1. 会话管理&#xff08;Session Management&#xff09;2. 个性化设置3. 追踪用户行…