Function
bool (dependentKey) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/computed_macros.js:321
import { bool } from '@ember/object/computed';
- dependentKey
- String
- returns
- ComputedProperty
- computed property which converts to boolean the original value for property
A computed property that converts the provided dependent property into a boolean value.
Example:
import { set } from '@ember/object'; import { bool } from '@ember/object/computed'; class Hamster { @bool('numBananas') hasBananas } let hamster = new Hamster(); hamster.hasBananas; // false set(hamster, 'numBananas', 0); hamster.hasBananas; // false set(hamster, 'numBananas', 1); hamster.hasBananas; // true set(hamster, 'numBananas', null); hamster.hasBananas; // false
Classic Class Example:
import EmberObject, { set } from '@ember/object'; import { bool } from '@ember/object/computed'; let Hamster = EmberObject.extend({ hasBananas: bool('numBananas') }); let hamster = Hamster.create(); hamster.hasBananas; // false set(hamster, 'numBananas', 0); hamster.hasBananas; // false set(hamster, 'numBananas', 1); hamster.hasBananas; // true set(hamster, 'numBananas', null); hamster.hasBananas; // false
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/bool