Mowzer Mowzer - 5 months ago 166
Javascript Question

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>

Answer

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 return true or false.