Page 1 of 1

Ionic4 Typescript to hide/show a component

Posted: Mon Jul 27, 2020 6:22 pm
by brendanm@ite.co.za

I am looking for the Typescript syntax to hide or show an Image component when a Button is clicked. I see some examples but not for Ionic 4 Typescript.


Re: Ionic4 Typescript to hide/show a component

Posted: Thu Jul 30, 2020 12:13 am
by Todd Mortensen

I would like some good example of this as well. I have been focusing on some other things in my app, but will be pivoting back this eventually.


Re: Ionic4 Typescript to hide/show a component

Posted: Thu Jul 30, 2020 1:56 pm
by Serhii Kulibaba

Hello,

It is pretty simple to do with *ngIf directive on any component you want to hide: https://angular.io/api/common/NgIf


Re: Ionic4 Typescript to hide/show a component

Posted: Fri Jul 31, 2020 7:16 am
by brendanm@ite.co.za

The ngIf works well. But I am struggling to get it to show/hide indiviual ListItems.

On my ListItem I have this:
*ngFor: let task of taskList
*ngIf: true

That does not work. I was hoping it would show all list items. In fact the app shows nothing when Tested.

Ultimately I want to show/hide list items based on an underlying value. So for example on each task:
*ngIf: task.taskName == 'abc'


Re: Ionic4 Typescript to hide/show a component

Posted: Thu Aug 06, 2020 3:12 pm
by Serhii Kulibaba

Hello,

You are right, the combination of ngFor and ngIf doesn't work there. Please see possible solutions here: https://stackoverflow.com/questions/346 ... sing-error


Re: Ionic4 Typescript to hide/show a component

Posted: Fri Aug 07, 2020 6:25 am
by brendanm@ite.co.za

Thanks for the link. I had already worked around it by doing all the *ngIf work in the background and then bound my list to a temp array which just contained the list items I wanted to show. Messy but workable


Re: Ionic4 Typescript to hide/show a component

Posted: Fri Aug 07, 2020 7:28 pm
by Serhii Kulibaba

Thank you for this update! Glad it works now!