我需要具有添加具有“热”值(订阅)的属性的功能,以便在满足条件时在菜单项上打勾。
我可以通过执行此操作来工作,但是我的解决方案似乎有些过分……
行为主体
//setup in the declarations
completedAssessments$ = new BehaviorSubject([]);
//in app init listening for changes to an array of completed assessments.
this.assessmentService.completedAssessments$.subscribe(res => { this.completedAssessments$.next(res); });
路线设置
this.pages.push({
title: 'General Experience',
url: '/general-experience',
icon: 'reader',
step: true,
completed: () => this.completedAssessments$.value.indexOf('generalExperience') > -1 //HELP! is there a better way to do this instead of making it a function like this? its the only way i could get it to be "HOT"
});
当强制返回true时,将显示该图标
<ion-item button [routerLink]="p.url" routerDirection="root" lines="none" detail="false" [class.selected]="selectedIndex == p.url"
*ngIf="(!p.children || p.children.length == 0)" [class.ion-hide]="!!p.hide && p.hide()">
<ion-icon slot="start" [ios]="p.icon + '-outline'" [md]="p.icon + '-outline'"></ion-icon>
<ion-label>{{ p.title }}</ion-label>
<ion-icon *ngIf="p.step && p.completed()" color="success" name="checkmark-outline" slot="end"></ion-icon>
</ion-item>