Observable condition in if binding

33 views
Skip to first unread message

Jodee Dex Page

unread,
Jun 9, 2016, 10:42:29 AM6/9/16
to KnockoutJS
If you have an observable bool property being used as the condition for a ko if: statement, why don't you have to use the unwrap syntax ()? 

Example from documentation:

<label><input type="checkbox" data-bind="checked: displayMessage" /> Display message</label>
 
<div data-bind="if: displayMessage">Here is a message. Astonishing.</div>
ko.applyBindings({
    displayMessage: ko.observable(false)
})


In other words, why isn't the syntax databind="if: displayMessage()"?  

or 

<!-- ko if: displayMessage() -->

Gunnar Liljas

unread,
Jun 9, 2016, 11:08:36 AM6/9/16
to knock...@googlegroups.com
If the only argument you give is an observable, Knockout will unwrap it for you.

<!-- ko if: displayMessage --> works

but you must write

<!-- ko if: displayMessage() && someOtherValue() -->

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jodee Dex Page

unread,
Jun 9, 2016, 11:34:23 AM6/9/16
to KnockoutJS
OK. Thanks for clarifying. 
Reply all
Reply to author
Forward
0 new messages