Using logical operator in knockout conditional if binding

user2585299 picture user2585299 · Oct 14, 2013 · Viewed 21.3k times · Source
<!-- ko if:name == 'Setup' || name == 'Appeals' -->
  <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret">/span>/button>
<!-- /ko -->

I am trying to show a button with a dropdown only when the name property contains the value "Setup" or "Appeals" but it does not work. Can we use logical operator in above knockout if binding ?

Answer

PW Kad picture PW Kad · Oct 14, 2013

When you are using a conditional statement inside of your binding remember that you need to 'get' the value -

<!-- ko if: name() === 'Setup' || name() === 'Appeals' -->
  <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret">/span>/button>
<!-- /ko -->