Polymer 1.0: Help using dom-if

Let Me Tink About It picture Let Me Tink About It · Jul 20, 2015 · Viewed 17.4k times · Source

Can someone please provide an example of proper implementation of dom-if?

No example of proper usage is provided by the official documentation. (Sorry there is no direct link. Must use menu in upper left and select dom-if).

Here is what I have so far. Obviously, it is not working.

<template>
  ...
  <template is="dom-if" if="{{action}}=='Login'">
       <!-- Also tried: if="{{action=='Login'}}" -->
    <a href="#">Forgot password?</a>
  </template>
  ...
</template>

Answer

agektmr picture agektmr · Jul 20, 2015

It's cumbersome, but you have to do this:

<template is="dom-if" if="[[_actionIsLogin(action)]]">
  <a href="#">Forgot password?</a>
</template>

<script>
  Polymer({
    ...
    _actionIsLogin: function(action) {
      return action === 'Login';
    }
    ...
  });
</script>

Explicitly create a function that returns either true or false.