3

How can I use expressions and filters in polymer 1.0?

How could I make this code snippet work?

<template>
  1 + 1: <span>{{ 1+1 }}</span>
</template>
Tamas
  • 3,254
  • 4
  • 29
  • 51

1 Answers1

9

Modify html like this:

1 + 1: <span>{{sum(1, 1)}}</span>

And add this function to Polymer script:

sum: function (a, b) {
    return a + b;
}

Currently there’s no general support for expressions in binding annotations. (source)

vasek
  • 341
  • 2
  • 4
  • Thanks for your answer, but that'd result such a bloat that I am not willing to have. E.g. for a simple loop, I don't want to have a script tag; But even if I have a script tag somewhere, the code gets spread all over the place, instead of a simple in-line expression. E.g. how would you solve [iterating over an object](http://stackoverflow.com/questions/30781500) in a clean way? – Tamas Jun 11 '15 at 13:59
  • Where should I put the sum function, if I have an expression in my index file ? – Florian Mozart Feb 20 '16 at 17:19
  • If you provide the iteration example, we might be able to help you over there ;) – aemonge Apr 22 '16 at 23:25