Getting a computed property from a component

355 Views Asked by At

I currently try to get a computed property from a component.

export default Component.extend({
    isValid: computed('currentQuantity', 'maxQuantity', function() { ... }),
});

Trying to receive it (controller: isValid=null;) with

{{quantity-list isValid=(mut isValid)}}

results in overwriting the property and removing the computation.

How can I get the isValid property?

2

There are 2 best solutions below

0
dguay On

Remove the mut helper when passing isValid property to your quantity-list component. The mut helper mutates the value when it changes in your child component. You should pass isValid like this:

{{quantity-list isValid=isValid}}

0
LAW On

Keep in mind any property value defined in the component is just a default, and if you pass in a property, it overwrites the default. So in this case, you passing in a property overwrites the default behavior, which is for isValid to be a computed.

In other words, you need to not pass a value in if you want your component to have isValid be a computed property.