Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

angular - Conditions on cssClass in Ionic

I'm taking over a mobile project at my new work, which has a badge system, on click, it displays a modal with the badge. I would like to display a small "V" image on it if the user owns the badge, which is easily done with some ngIf, but in this case the previous developer is using the modalController which takes cssClass as an attribute for styling, is there a way to make conditional statements on this or will I have to recreate a modal on my own? Here's the modal code:

        const modal = await this.modalCtrl.create({
            component: ModalBadgePage,
            cssClass: 'modal-badge',
            mode: 'md',
            componentProps: {
                // id: currentId,
                title: badgeTitle,
                description: badgeDescription,
                image: badgeImage,
                hunts: badgeHunts
            }
        });

Thank you !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can add your condition like below mentioned .. where 1==1 is the condition check and if this is true it will add modal-badge class else it will add modal-badge2 class to this modal

const modal = await this.modalCtrl.create({
            component: ModalBadgePage,
            cssClass: (1==1) ? 'modal-badge' : 'modal-badge2',
            mode: 'md',
            componentProps: {
                // id: currentId,
                title: badgeTitle,
                description: badgeDescription,
                image: badgeImage,
                hunts: badgeHunts
            }
        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...