How to get checkbox state in ember.js?

by cortez.connelly , in category: Javascript , 4 months ago

How to get checkbox state in ember.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 4 months ago

@cortez.connelly 

You can get the checkbox state in Ember.js by using the checked attribute.

  1. In your template file, you can bind the checkbox state to a property in your component or controller like this:
1
<input type="checkbox" checked={{checkboxState}} {{action 'toggleCheckbox'}}>


  1. In your component or controller file, define the property and handle the toggle action:
1
2
3
4
5
6
7
8
checkboxState: false,

actions: {
  toggleCheckbox() {
    this.toggleProperty('checkboxState');
    console.log(this.get('checkboxState')); // This will log the current state of the checkbox
  }
}


Now, whenever the checkbox is clicked, the checkboxState property will toggle between true and false, and you can access its current state in your component or controller.