Css negation giving type error

55 views Asked by At

In my model I have

self.isAssetForTradingEnabled = false;

and when I try to bind it to add some style like this:

<tr data-bind="css: { 'selected': quantity() > 0 , 'disabled': !isAssetForTradingEnabled() }">

Then Knockout gives a type error.

It works if I change

isAssetForTradingEnabled = true;

and

'disabled': isAssetForTradingEnabled
1

There are 1 answers

0
Jeroen On BEST ANSWER

If you have this...

self.isAssetForTradingEnabled = false;

...you should not do this...

'disabled': !isAssetForTradingEnabled()

...because isAssetForTradingEnabled is not a(n observable) function. Instead either do this...

'disabled': !isAssetForTradingEnabled

...or change your view model to this...

self.isAssetForTradingEnabled = ko.observable(false);

Note that you need the latter if you want the view to respond to changes in isAssetForTradingEnabled, because plain (non-observable) members aren't tracked.