Scott Scott - 22 days ago 4x
CSS Question

Passing parameter to web component to use in class fails

I have the following code in a element that works fine:

<i class="fa fa-user"></i>

However, I want to change the icon based on a parameter. So I changed that line to this:

<i class="fa fa-{{icon}}"></i>

And then I added the following property to the Polymer element:

icon: {
type: String,
value: 'user'

Running it as is, without even trying to pass a different value and just letting it use the default
, it doesn't render properly. The DOM just has this:

<i class="style-scope widget-iconblock"></i>

I've tried a few other things, including replacing the entire
tag with
then having that return a calculated value similar to
"<i class='fa fa-" + self.icon + "'></i>"
but that rendered the literal text.

What am I doing wrong?


Binding properties to native attributes requires Polymer's attribute-binding syntax (i.e., class$="{{prop}}"):

  <base href="">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="polymer/polymer.html">
  <link rel="stylesheet" href="">

  <dom-module id="x-foo">
      <i class$="fa fa-{{icon}}"></i>
    HTMLImports.whenReady(function() {
        is: 'x-foo',
        properties : {
          icon: {
            type: String,
            value: 'user'