Polymer Method Binding

When using Polymer, is it possible to bind a method, not a value? For instance.

<div>{{someMethod()}}</div>

or

<div>{{someMethod}}</div>

Judging by the source and documents, this is not so. Just wanted to confirm.

+3
source share
1 answer

Not directly, but there are several ways to possibly achieve what you want. I assume you want to convert the data ...?

  • Define the property as an ES5 getter

    A little cheating, but you can define the property as a getter and then wrap your own logic around the return value.

    <div>{{likes}}</div>
    
    Polymer('my-tag', {
      firstName: 'John',
      get likes() {
        return this.firstName + ' ' + lastName + ' likes bread';
      }
    });
    

    Demo: http://jsbin.com/nuyuqote/3/edit

    . . Object.observe(), , . . .

  • : (

    <div>{{'thingy' | upperCaseFilter}}</div>
    
    Polymer('my-tag', {
      upperCaseFilter: function(value) {
        return value.toUpperCase();
      }
    });
    

    : http://jsbin.com/nuyuqote/1/edit

  • <prop>Changed

    .

, , - {{someMethod()}} Polymer, - , JavaScript. -, - onclick="someMethod()", , XSS.

+3