Is there a way to pass an argument to a Polymer function from an element attribute inside its <template>
?
<script src="http://www.polymer-project.org/1.0/samples/components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="http://www.polymer-project.org/1.0/samples/components/polymer/polymer.html" />
<dom-module id="example-element">
<template>
...
<paper-button id="foo" on-tap="bar">Click</paper-button>
...
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'example-element',
properties: {...},
bar: function(arg){
// Do stuff using argument arg
}
});
})();
</script>
Background Research
I have combed through the documentation which appears silent on the matter. It doesn't say whether you can or can not. But when I try it, it fails. But maybe I'm not doing it correctly. So I need some assistance.
The only thing I have come across is event listeners which doesn't seem to be able to take the arguments I want to pass. Say, an id
or a name
.
Previous Attempts
I have tried (unsuccessfully) doing things like:
<paper-button id="foo" on-tap="bar('foo')"> Click </paper-button>
but nothing seems to work.
The event listeners idea doesn't work because they limit the arguments and I can't get the, say, id
I need.
on-tap="bar" data-bar="foo"
, then in your event handler,e.srcElement.getAttribute('data-bar')
. You can't pass an argument like you tried to do. – Let Me Tink About It