Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer 1.0: Help using dom-if

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>
like image 965
Let Me Tink About It Avatar asked Jul 20 '15 08:07

Let Me Tink About It


1 Answers

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.

like image 51
agektmr Avatar answered Oct 24 '22 20:10

agektmr