angular - 如何从打字稿文件中隐藏 mat-checkbox
问题描述
我需要根据在我的应用程序中更改的选项卡选择隐藏文件中的mat-checkbox
控件。typescript
这是html
文件代码
<mat-checkbox (change)="OnChangeRed($event)" id="check1" class="example-margin" [checked]="matCheckboxRed"></mat-checkbox>
同一html
文件中的选项卡
<div>
<mat-tab-group #tabRef (selectedTabChange)="tabChanged(tabRef.selectedIndex)">
<mat-tab label="ALL"></mat-tab>
<mat-tab label="Actvie"></mat-tab>
<mat-tab label="Inactive"></mat-tab>
<mat-tab label="Deliverted"></mat-tab>
</mat-tab-group>
</div>
当我的标签更改呼叫时,我需要隐藏复选框
tabChanged(index)
{
}
我怎样才能做到这一点
解决方案
您可以将 ngModel 与复选框一起使用,如下所示:
<mat-checkbox *ngIf="show" (change)="OnChangeRed($event)" id="check1" class="example-margin" [checked]="matCheckboxRed"></mat-checkbox>
在 tabChanged 事件中,您可以根据已触发的选项卡更改显示值:
show: boolean = true;
tabChanged(index)
{
if(index == "your tab index"){
this.show = false;
}
}
使用 ViewChild 的另一种方法:
<mat-checkbox #checkbox (change)="OnChangeRed($event)" id="check1" class="example-margin" [checked]="matCheckboxRed"></mat-checkbox>
并在 ts 文件中:
@ViewChild('checkbox') el:ElementRef;
tabChanged(index)
{
if(index == "your tab index"){
this.el.nativeElement.style.display='none';
}
}
推荐阅读
- python - 如何从 Dask 数据框中选择 n 个等距的行?
- c++ - 是否可以在调用函数模板时只指定一些模板参数,让编译器推导出其他参数
- flutter - Flutter 动画包 - 当用户导航返回时如何等待 Navigator.push() 做某事
- c# - MySQL:从 C# 批量发送 20000 SELECT 查询
- java - WebClient builder Post Call 在 Webflux 中首次给出错误请求错误
- angular - 如何在剑道日期选择器中将过去日期显示为禁用日期
- r - R ggplot - 使用“stat_compare_mean”时每个面板的不同 y 轴
- python - 合并两个熊猫数据框,其中一个是另一个的子集(或仅填充列的子集)
- json - 首次启动颤振时保存和检索 json 对象
- c# - 尝试将列表转换为数组会产生“错误 CS1503:参数 1:无法从 'System.Collections.Generic.List 转换
' 到 'System.Array' "