How to create boolean function on Ionic


Hello guys,

I’m trying to implement two functions to one button.
For instance, I want to create one button which can turn on and off modal.

<button (click)="openModal()" ion-button>Modal On / Off</button>

What would be my typescript and how can I pass in boolean to this set up?

openModal() {
  const myModal = this.modal.create('ModalPage');

This current button will only open up modal… but I want to be able to turn it off once clicking on this button again.




This simple function should answer your question,

Hope that helps,


Or you could simply set the value type before declaration,

aka this,


openModal() {
  let myModal : boolean = true;
  const myModal = this.modal.create('ModalPage');

You can try this, not tested at my code,

Hope this helps,



they didn’t really help… other opinions would be appreciated.



@jamesharvey after i think you can’t assign both a boolean declaration and a const, not sure, i’m not a super expert in TypeScript. Anyways dig into typescript because that’s what our code is about.

Good luck,



In your component:

  private boolean: isModalVisible = false;

  public toggleModal() {

    if (this.isModalVisible === false) {
      this.isModalVisible = true;
      // show Modal
    } else {
      this.isModalVisible = false;
      // hide Modal

One button can do 2 function

@robinyo @jamesharvey looks like the solution, thank you Robinyo :slight_smile:


Will try that now.

Thanks a lot… I see why mine wasn’t working… I was using only two ==


so now it works @jamesharvey ?