Skip to content

Latest commit

 

History

History
117 lines (87 loc) · 3.71 KB

File metadata and controls

117 lines (87 loc) · 3.71 KB

Table Component

Reusable table which allows to inject arbitrary caption, header, body and footer.

Table Of Content

Usage

Browser's result

Browser's result of the table component

Angular template excerpt

app.component.html

The styles of this table are in table.component.css. (2)

<app-table [data]="employeeList">

  <ng-template #TableCaption>Staff</ng-template>

  <ng-template #TableHeader>
    <th>Id</th>
    <th>Name</th>
    <th>Surname</th>
    <th>Age</th>
    <th>foo()</th>
  </ng-template>

  <ng-template #TableBody let-employee>
    <td>{{employee.id}}</td>
    <td>
      <a href="#">{{employee.name}}</a>
    </td>
    <td>{{employee.surname}}</td>
    <td>{{employee.age}}</td>
    <td>
      <button type="button" (click)="foo(employee)">{{employee.name}}</button>
    </td>
  </ng-template>

  <ng-template #TableFooter>
    <th>Id</th>
    <th>Name</th>
    <th>Surname</th>
    <th>Age</th>
    <th>foo()</th>
  </ng-template>

</app-table>

Angular classes

app.component.ts (excerpt)

···

employeeList = STAFF;

···

staff.stub.ts

import { Employee } from './employee.model';

export const STAFF: Array<Employee> = [
  new Employee(1, 'Mary', 'Smith', 35),
  new Employee(2, 'John', 'Doe', 53),
];

employee.model.ts

export class Employee {

  constructor(
    public readonly id:      number,
    public readonly name:    string,
    public readonly surname: string,
    public readonly age:     number,
  ) {}

}

Content Projection Resources