Is this possible to have if-else statement when using knockout container less statements? I mean Something like:
<!-- ko else -->
Is this possible to have if-else statement when using knockout container less statements? I mean Something like:
<!-- ko else -->
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 -->
Unfortunately there is no <!-- ko else -->
. you will need to use two <!-- ko if: something-is-true -->
statements or use templates to achieve the same thing as @huocp mentioned with the link to Knockout JS If-Else bindings
One solution already mentioned in above answers using ifnot.But you can use same this way
<!-- ko if: myFlag -->
..if statement work here
<!-- /ko -->
<!-- ko if: !(myFlag) -->
..else statement work here
<!-- /ko -->