Is this possible to have if-else statement when using knockout container less statements? I mean Something like:
<!-- ko else -->
If the condition evaluates to true or true-like value, then the given HTML markup will be processed. Else, it will be removed from DOM. If the condition in the parameter contains an observable value, then the condition is re-evaluated whenever the observable value changes.
The if binding causes a section of markup to appear in your document (and to have its data-bind attributes applied), only if a specified expression evaluates to true (or a true -ish value such as a non- null object or nonempty string).
KO is that it updates your UI automatically when the view model changes.
Knockout. js is a minimalist JavaScript framework for web application development. It is a JavaScript library that allows binding HTML elements against any data model. It is primarily used for creating rich and responsive display as well as editor user interfaces with a clean, underlying data model.
As mentioned, there isn't an else
, but it's common to combine ko if
and ko ifnot
using the same flag.
<!-- ko if: myFlag --> ...some stuff for the true case <!-- /ko --> <!-- ko ifnot: myFlag --> ...some stuff for the else (false) case <!-- /ko -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With