我的 samplepage.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-batchticketvalidation',
templateUrl: './batchticketvalidation.component.html',
styleUrls: ['./batchticketvalidation.component.css']
})
export class BatchticketvalidationComponent {
constructor() { }
displayedColumns = ['id', 'ticketnumb', 'actionsColumn'];
dataSource: PeriodicElement[] = ELEMENT_DATA;
private myDataArray: any;
deleteTicket(rowid: number) {
if (rowid > -1) {
this.myDataArray.splice(rowid, 1);
}
}
}
export interface PeriodicElement {
id: number;
ticketnumb: string;
actionsColumn: any;
}
const ELEMENT_DATA: PeriodicElement[] = [
];
我的 samplepage.component.html
<table mat-table [dataSource]="myDataArray" >
<!-- <ng-container [matColumnDef]="column" *ngFor="let column of displayedColumns" >
<th mat-header-cell *matHeaderCellDef > {{column}} </th>
<td mat-cell *matCellDef="let element" > {{element[column]}} </td>
</ng-container> -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Id. </th>
<td mat-cell *matCellDef="let element; let i = index;"> {{i+1}} </td>
</ng-container>
<ng-container matColumnDef="ticketnumb">
<th mat-header-cell *matHeaderCellDef> Ticket Number </th>
<td mat-cell *matCellDef="let element"> {{element.ticketnumb}} </td>
</ng-container>
<ng-container matColumnDef="actionsColumn">
<th mat-header-cell *matHeaderCellDef> Action </th>
<td mat-cell *matCellDef="let element; let j = index;">
<button mat-raised-button color="warn" focusable="false" (click)="deleteTicket(j)">
<i class="fa fa-times mat-icon"></i> Remove
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
我是角度的新手。我需要帮助从表中删除特定行,一旦删除该行,表应该得到刷新或者它应该显示现有数据。我只有静态行。这只是我想向客户展示的简单的样机 html。
每行都有删除按钮,单击删除按钮我调用 deleteTicket(rowid)。
当 deleteTicket 方法被触发时,该行不会从 Ui 中删除,但是当我控制台 this.myDataArray 时,数据会从对象中删除。
我尝试了所有的可能性。