angular - Angular Material mat-cell datepicker 将自定义 ID 传递给事件处理函数
问题描述
我在 mat-cell 中添加了一个 Angular Material mat-datepicker。When the datepicker is selected and the date is changed it will call a function in the typescript side. 我试图在 mat-table 绑定期间弄清楚如何将记录的 ID(主键)绑定到该 mat-cell 并将该值传递给事件处理函数。到目前为止,这是我的代码
<ng-container matColumnDef="ProcessDate">
<mat-header-cell *matHeaderCellDef mat-sort-header><strong>{{columnName}}</strong></mat-header-cell>
<mat-cell id={{mydata.id}} *matCellDef="let mydata">
<input id={{mydata.id}} class="control-width" matInput [matDatepicker]="picker1" [value]="myData.date" (dateChange)="addEvent(id, $event)">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1 color="primary"></mat-datepicker>
</mat-cell>
</ng-container>
在打字稿方面,id 是“未定义的”。任何帮助表示赞赏。
解决方案
如果您想要的 id 是 mydata.id 属性,请将回调中的 id 更改为 mydata.id。该视图中没有 id 属性,除非您的组件上有名为 id 的属性,否则 id 将是未定义的。
推荐阅读
- node.js - 像 Youtube 一样的视频流,在 Node js 中播放的主要视频之间有广告视频
- android - 如何在项目中找到墙纸 URL?
- asp.net - Global.asax Application_Error IIS7WorkerRequest.RaiseCommunicationError.ExplicitFlush()
- java - 如何用新字符替换字符串中的第 n 个字符?
- php - php mailer Getting SMTP connect() failed 突然出错,休息正常
- javascript - 让 taskRunner 运行时遇到问题
- bash - 如何在子 shell 中使用 grep 命令?
- php - 每 3 小时运行一次请求
- ruby - 安装自制软件时出现LoadError
- vbscript - VBScript 文件重命名:“文件已存在”错误