Angular 在mat表上调用renderRow()时出现问题
我想在单击按钮时将行添加到“按材质”表中。但是我似乎无法让renderRows()方法在我的表上调用 以下是我的代码中的一些相关部分:Angular 在mat表上调用renderRow()时出现问题,angular,angular-material2,Angular,Angular Material2,我想在单击按钮时将行添加到“按材质”表中。但是我似乎无法让renderRows()方法在我的表上调用 以下是我的代码中的一些相关部分: <div fxFlex="20%" fxLayout="row" fxLayoutAlign="center"> <input fxFlex="10%" matInput placeholder="Part #" type="number" [(ngModel)]="partNumber"> <inp
<div fxFlex="20%" fxLayout="row" fxLayoutAlign="center">
<input fxFlex="10%" matInput placeholder="Part #" type="number" [(ngModel)]="partNumber">
<input fxFlex="20%" matInput placeholder="Video Url" type="text" [(ngModel)]="videoUrl">
<input fxFlex="40%" matInput placeholder="Download Url" type="text" [(ngModel)]="downloadUrl">
<button mat-button [disabled]="partNumber == null || videoUrl == null" (click)="addVideo()"> <-- I would like my table to update on this click
Add Video
</button>
</div>
<div *ngIf="urlCollection.length > 0">
<mat-table #videoTable videoTable [dataSource]="dataSource">
<-- Table columns -->
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
我尝试在按钮单击事件中调用renderRows(),如下所示:
<button mat-button [disabled]="partNumber == null || videoUrl == null" (click)="addVideo(); videoTable.renderRows()">
<button mat-button [disabled]="partNumber == null || videoUrl == null" (click)="addVideo(); videoTable.table.renderRows()">
@ViewChild('videoTable') videoTable: MatTableModule;
// rest of the component
addVideo()
{
// add to the datasource collection
this.videoTable.renderRows();
}
我得到一个“属性'renderRows'在类型'MatTableModule'上不存在”错误
单击按钮并更新数据源时,如何更新我的表 您使用错误的类型声明了
videoTable
,它应该是MatTable
尝试以下代码示例:
import { MatTable } from '@angular/material';
@ViewChild('videoTable') videoTable: MatTable<your type>;
// rest of the component
addVideo()
{
// add to the datasource collection
this.videoTable.renderRows(); // call from typescript
}
// template example
// call renderRows() directly from videoTable
<button mat-button [disabled]="partNumber == null || videoUrl == null" (click)="addVideo(); videoTable.renderRows()">
从'@angular/material'导入{MatTable};
@ViewChild(“videoTable”)videoTable:MatTable;
//组件的其余部分
addVideo()
{
//添加到数据源集合
this.videoTable.renderRows();//从typescript调用
}
//模板示例
//直接从videoTable调用renderRows()
请参阅工作
import { MatTable } from '@angular/material';
@ViewChild('videoTable') videoTable: MatTable<your type>;
// rest of the component
addVideo()
{
// add to the datasource collection
this.videoTable.renderRows(); // call from typescript
}
// template example
// call renderRows() directly from videoTable
<button mat-button [disabled]="partNumber == null || videoUrl == null" (click)="addVideo(); videoTable.renderRows()">