0

I"m pulling data from an API right now and depending on if the user is logged in or not I want to display a login prompt. I can do this by having two divs each with their own *ngIf="cond" but this is a lot of duplicate code. Is there a way using Ionic 3 + Angular to only have the (click) attribute if a condition is met, otherwise leave it off?

Any help would be great.

Joe Scotto
  • 10,936
  • 14
  • 66
  • 136
  • you could set display to none on the button by using `Renderer`'s `setElementStyle` to add `'display', 'none'` to the button when the condition is met, and change it to `block` or whatever it needs to be when the condition is not met. If you provide some code I can show you how it works – ewizard Nov 28 '17 at 21:28
  • Another way to do it would be to still handle the `click` event, and add a condition as the first line of the handler `yourMethod() { if(shouldLeave) return; // ...}` to check if you need to do something or just ignore the click – sebaferreras Nov 28 '17 at 22:10

0 Answers0