angular - 数据绑定到组件后如何触发函数或什么事件?
问题描述
我在我的 angular 10 项目中使用 angular material select。
这是模板:
<mat-form-field appearance="fill">
<mat-select [(ngModel)]="defaultSelection" (selectionChange)="onSelect($event)">
<mat-option *ngFor="let name of enumKeys" [value]="name">
{{enum[name]}}
</mat-option>
</mat-select>
</mat-form-field>
这是组件:
export class EnumSelectionComponent implements OnInit {
@Input() enum: Object = Status;
defaultSelection = Status.Info;
enumKeys=[];
constructor() {
this.enumKeys=Object.keys(this.enum);
}
onSelect(selection) {
alert(selection)
}
ngOnInit(): void {}
}
在 *ngFor 指令中生成选择选项后,我需要触发一个函数。
我的问题是我怎么知道选项是在 *ngFor 指令中生成的,我是否有任何迹象表明我可以运行一些事件处理程序?
解决方案
推荐阅读
- pandas - 比较数据框中的特定行
- jquery - 在交叉单元格处切换类导致问题
- ios - 如何在 project.pbxproj 文件中使用环境变量?
- laravel - laravel中的dompdf处理缓慢
- python - Telethon API - 为什么我的 api_id 和 api_hash 不刷新?
- regex - EML Base64 块的正则表达式
- r - 用多个时间序列在 GGPLOT 中绘制图例
- python - 使用 shift 和 groupby 计算
- bash - 使用 bash 中的另一个文件替换 txt 文件中的多行
- python - 如何在 python 中同时使用 .join() 和 .format()