我有一个导航栏,它使用默认为“家庭中的所有猫”的切换栏(类似于切换按钮)。当开关关闭时,它旁边会显示默认的“家庭中的所有猫”标签,并显示家庭中所有猫的表格。这工作正常,后端/数据按预期工作。
但是,当开关打开(又名单击)时,我希望开关栏标签显示“我的猫”并显示仅显示我的猫的表格。我真的不明白如何获取“allCatsTable”的布尔值的值,因为该值是在导航栏中设置的。有人可以帮助初学者学习如何做到这一点吗?
我省略了一些代码以使我的问题更清楚。
猫.component.ts
export class CatComponent implements OnInit {
tableName: string;
gridPage: string;
constructor(private router:Router, public tableRefineHelper: tableRefineHelper) {
if (isAllCatsTable) {. <--- how do I get this value from the navBar?
this.tableName = workloadName.allCats;
this.gridPage = 'allCats'
} else {
this.gridPage = 'myCats';
this.workloadName = workloadName.myCats;
}
}
ngOnInit(): void {
}
}
actionbar.component.html
<div class="actionbar">
<div *ngIf="isAllCatsTable || isMyCatsTable">
<igx-switch labelPosition="after" (change) = "onSwitchClick($event)"
checked="false">{{switchName}}</igx-switch>
</div>
</div>
actionbar.component.ts
export class ActionbarComponent implements OnInit, OnChanges {
isAllCatsTable: boolean;
isMyCatsTable: boolean;
switchName: string = "All Cats in the Family";
constructor() { }
public onSwitchClick(event) {
if (event.checked) {
this.switchName = "All Cats in the Family";
} else {
this.switchName = "My Cats";
}
}