customer-table.component.ts
angular/examples/week07-08/src/app/customer-table.component.ts
// @ts-nocheck
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { NgFor, NgIf } from '@angular/common';
import { Customer } from './customer.service';
import { HasPermissionDirective } from './has-permission.directive';
@Component({
selector: 'app-customer-table',
standalone: true,
imports: [NgFor, NgIf, HasPermissionDirective],
template: `
<section>
<header class="header">
<h2>Customers</h2>
<button type="button" appHasPermission="admin" (click)="create.emit()">New Customer</button>
</header>
<table *ngIf="customers.length; else empty">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let customer of customers">
<td>{{ customer.name }}</td>
<td>{{ customer.email }}</td>
<td>
<span class="status" [class.inactive]="customer.status === 'inactive'">
{{ customer.status }}
</span>
</td>
<td>
<button type="button" (click)="edit.emit(customer)">Edit</button>
<button type="button" appHasPermission="admin" (click)="remove.emit(customer)">Delete</button>
</td>
</tr>
</tbody>
</table>
<ng-template #empty>
<p>No customers yet. Create your first record.</p>
</ng-template>
</section>
`,
styles: [
`
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
padding: 0.75rem;
border-bottom: 1px solid #e5e7eb;
}
button {
margin-inline-end: 0.5rem;
}
.status.inactive {
color: #dc2626;
}
`,
],
})
export class CustomerTableComponent {
@Input() customers: Customer[] = [];
@Output() create = new EventEmitter<void>();
@Output() edit = new EventEmitter<Customer>();
@Output() remove = new EventEmitter<Customer>();
}
相关文章
server.js
server.js — javascript source code from the angular learning materials (angular/comprehensive-demo/server/server.js).
阅读文章 →app.component.ts
app.component.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.component.ts).
阅读文章 →app.config.ts
app.config.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.config.ts).
阅读文章 →app.routes.ts
app.routes.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.routes.ts).
阅读文章 →auth.guard.ts
auth.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/auth.guard.ts).
阅读文章 →role.guard.ts
role.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/role.guard.ts).
阅读文章 →