angular - 有没有办法在 Typescript 和 Angular 中为“let variable”类型输入提示 IDE?
问题描述
有像这样的标记
<mat-cell *matCellDef="let request">
<a [href]="request.url" target="_blank">{{request.requestId}}</a>
</mat-cell>
我可以以某种方式输入提示 IDE 该请求是类型的Request
吗?我在这里使用 IntelliJ。
请注意,我在这里使用 Angular Material 表,因此request
在组件中声明不是一个选项,因为它纯粹是模板变量。它包含组件本身在每次行迭代时内部提供的行数据。
请注意,这是在 MatDataTable 组件中使用的完全有效的标记。
解决方案
作为
tableDataSource: MatTableDataSource<ToDoInterface>;
不键入模型,
这个:
<ng-container matColumnDef="toDo">
<th mat-header-cell *matHeaderCellDef mat-sort-header>ToDo</th>
<td mat-cell *matCellDef="let model">
<ng-container *ngIf="assertItemType(model) as toDoModel">
{{toDoModel.toDo}}
</ng-container>
</td>
</ng-container>
在哪里:
assertItemType(item: ToDoInterface): ToDoInterface {
return item;
}
作品。
但不确定这是否是最好的方法
推荐阅读
- powershell-5.0 - 使用powershell在文件中进行字符串处理
- angular - Angular 中的可选链
- kotlin - 当我只想执行 kotlin 脚本时,为什么 IntelliJ IDEA 正在构建 maven 项目?
- python - 异常处理 - 列表索引超出范围
- python - 我应该如何使用 asyncio 设计并发管道?
- firebase - 断言失败:第 133 行第 12 行:'file.absolute.existsSync()':不正确
- google-cloud-platform - GCP 中的 Kubeflow 元数据存储
- c# - 如何通过 aspose.diagram 将文本的方向更改为 rtl
- java - 在mac中执行hadoop jar命令需要更长的时间来解压并开始处理
- javascript - 微前端架构和 css 和 js 挑战