小编Web*_*ner的帖子

Angular 6:如何在Angular材质表上实现分页和排序

如何在Angular Material DataTable中传递我的API服务数据。我想呈现我的数据而不是此静态数组。如果我像*ngFor="let item of service.list"这样渲染数据,则数据已加载,但分页和排序不起作用。请为此提供一些解决方案或示例。

import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';

export interface PeriodicElement {
  name: string;
  position: number;
  weight: number;
  symbol: string;
}

const ELEMENT_DATA: PeriodicElement[] = [
  {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
  {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
  {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}
];

@Component({
  selector: 'app-root',
  styleUrls: ['./app.component.css'],
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit …
Run Code Online (Sandbox Code Playgroud)

angular-material angular

5
推荐指数
1
解决办法
1011
查看次数

标签 统计

angular ×1

angular-material ×1