我想通过 Angular material design 的数据表 mat-table 显示一个列表。这是我的组件:
import { LeaveapplicationService } from './../../services/leaveapplication.service';
import { leaveapplication } from './../../models/leaveapplication';
import { Component, OnInit, ViewChild, Input } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
// import { DataSource } from '@angular/cdk/table';
@Component({
selector: 'app-leaveapplication-list',
templateUrl: './leaveapplication-list.component.html',
styleUrls: ['./leaveapplication-list.component.scss']
})
export class LeaveapplicationListComponent implements OnInit {
leaveApplications: leaveapplication[];
displayedColumns: ['id', 'applicant', 'manager', 'leavetype', 'start', 'end', 'return', 'status'];
dataSource: MatTableDataSource<leaveapplication>;
constructor(private leaveApplicationService: LeaveapplicationService) { }
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: …Run Code Online (Sandbox Code Playgroud) 我正在使用带有可扩展行的材料表
我想在行单击时展开多行。默认行为是在单击新行时关闭先前展开的行。我不想关闭前面的那些,每个都应该保持打开状态,直到再次单击。我怎样才能做到这一点?
我在模板中为 Observable 使用异步管道:
applicants$: Observable<UserProfile[]>;
ngOnInit() {
this.applicants$ = this.store.pipe(
select(fromRootUserProfileState.getUserProfiles)
) as Observable<UserProfile[]>;
}
Run Code Online (Sandbox Code Playgroud)
这是 UserProfile.ts 界面:
import { Role } from './role/role';
import { Country } from './Country';
export interface UserProfile {
id?: number;
fullName?: string;
roles?: Role[];
windowsAccount?: string;
firstName?: string;
lastName?: string;
email?: string;
managerName?: string;
managerId?: number;
managerEmail?: string;
companyId?: number;
companyName?: string;
countryId?: number;
country?: Country;
countryName?: string;
}
Run Code Online (Sandbox Code Playgroud)
这是 userProfile.service
getUserProfiles(): Observable<UserProfile[]> {
return this.http.get<UserProfile[]>(
this.baseUrl + 'userprofiles/getuserprofiles'
);
}
Run Code Online (Sandbox Code Playgroud)
在模板中,我使用 ngFor 通过异步管道遍历 …