Как я могу добавить и удалить динамическую строку, используя угловой материал mat-table
. Предложите мне несколько методов, я добавил столбцы и добавил к ним отступы, но я не могу добавить вторую строку.
displayedColumns = ['position', 'name', 'weight', 'symbol','extra','Action'];
displayedColumnsAddUser: string[] = ['position', 'name', 'weight', 'symbol', 'extra', 'Action'];
dataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
}
const ELEMENT_DATA: Element[] = [
{name: '',position:1, weight:'' , symbol:'', extra:'',Action:''},
];
export interface Element {
name: string;
position:number;
weight: string;
symbol: string;
extra :string;
Action:string;
}
<link href = "https://fonts.googleapis.com/icon?family=Material+Icons" rel = "stylesheet">
<div class = "example-container mat-elevation-z8" style = "width: 75%;
margin-left: 78px;">
<mat-table class = "custom" [dataSource] = "dataSource">
<ng-container matColumnDef = "position">
<mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
<mat-cell *matCellDef = "let element">
<!-- <mat-form-feild>
<input matInput placeholder = "placeholder" [(ngModel)] = "element.position">
</mat-form-feild> -->
{{element.position}}
</mat-cell>
</ng-container>
<ng-container matColumnDef = "name">
<mat-header-cell *matHeaderCellDef> Protocol </mat-header-cell>
<mat-cell *matCellDef = "let element"> {{element.protocol}} </mat-cell>
</ng-container>
<ng-container matColumnDef = "weight">
<mat-header-cell *matHeaderCellDef> SourceIp </mat-header-cell>
<mat-cell *matCellDef = "let element"> {{element.SourceIp}} </mat-cell>
</ng-container>
<ng-container matColumnDef = "symbol">
<mat-header-cell *matHeaderCellDef> DestinationIp </mat-header-cell>
<mat-cell *matCellDef = "let element"> {{element.DestinationIp}} </mat-cell>
</ng-container>
<ng-container matColumnDef = "extra">
<mat-header-cell *matHeaderCellDef>AcessType </mat-header-cell>
<mat-cell *matCellDef = "let element"> {{element.AcessType}} </mat-cell>
</ng-container>
<ng-container matColumnDef = "Action">
<mat-header-cell *matHeaderCellDef>Action </mat-header-cell>
<mat-cell *matCellDef = "let element"> {{element.Action}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef = "displayedColumns"></mat-header-row>
<mat-row *matRowDef = "let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
<script type = "text/javascript" src = "https://js.squareup.com/v2/paymentform"></script>
🤔 А знаете ли вы, что...
Один из ключевых принципов Angular - это двунаправленное связывание данных, которое автоматически обновляет интерфейс при изменении данных и наоборот.