cosmichero2025
cosmichero2025

Reputation: 1029

Polymer dom-repeat attribute is not working

I've been following a tutorial and trying things out for myself for a basic contact list. When the different sections where not inside a dom-repeat template they showed up just fine within the component. After using the dom-repeat from the polymer website they no longer show up.

index.html

<!doctype html>

<html lang="en">

<head>
  Everything is linked correctly
</head>

<body>
    <aside>
    <contact-list></contact-list>
    </aside>
</body>

</html> 

componenent.html

    <link rel="import" href="bower_components/polymer/polymer.html">

    <dom-module id="contact-list">

        <style>
            ul {
                list-style: none;
            }

            li {
                display: flex;
                padding: 20px;
            }

            li img {
                border-radius: 50%;
                margin-right: 10px;
            }

        li + li {
            border-top: solid 1px #666;
        }

        h3 {
            margin-right: 0 40px 0 0;
            line-height: 80px;
        }

        li span {
            line-height: 120px;
            margin-left: 20px;
        }
    </style>

    <template>
        <ul>
            <template is="dom-repeat" items="{{contact}}">
                <li>
                    <img src="{{item.img}}" alt="User Photo">
                    <h3>{{item.name}}</h3>
                    <span>{{item.email}}</span>
                </li>
            </template>
        </ul>
    </template>
</dom-module>

<script>
Polymer({
    is: "contact-list",
    ready: funtion() {
        this.contact = [
            {
                name: "Scott",
                email: "[email protected]",
                img: "https://randomuser.me/api/portraits/men/45.jpg"
    }

            , {
                name: "Tim",
                email: "[email protected]",
                img: "https://randomuser.me/api/portraits/men/28.jpg"
    }

            , {
                name: "Ben",
                email: "[email protected]",
                img: "https://randomuser.me/api/portraits/men/68.jpg"
    }
        ]
    }

});
</script>

Upvotes: 2

Views: 266

Answers (1)

tony19
tony19

Reputation: 138196

You have a typo in:

ready: funtion() {

That should be function with a "c". Fixing that was enough to get your code working for me (see demos below).

<head>
  <base href="https://polygit.org/polymer+1.6.0/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link rel="import" href="polymer/polymer.html">
</head>

<body>
  <contact-list></contact-list>

  <dom-module id="contact-list">
    <style>
      ul {
        list-style: none;
      }
      li {
        display: flex;
        padding: 20px;
      }
      li img {
        border-radius: 50%;
        margin-right: 10px;
      }
      li + li {
        border-top: solid 1px #666;
      }
      h3 {
        margin-right: 0 40px 0 0;
        line-height: 80px;
      }
      li span {
        line-height: 120px;
        margin-left: 20px;
      }
    </style>

    <template>
      <ul>
        <template is="dom-repeat" items="{{contact}}">
          <li>
            <img src="{{item.img}}" alt="User Photo">
            <h3>{{item.name}}</h3>
            <span>{{item.email}}</span>
          </li>
        </template>
      </ul>
    </template>
    <script>
      HTMLImports.whenReady(function() {
        Polymer({
          is: "contact-list",
          ready: function() {
            this.contact = [{
              name: "Scott",
              email: "[email protected]",
              img: "https://randomuser.me/api/portraits/men/45.jpg"
            }, {
              name: "Tim",
              email: "[email protected]",
              img: "https://randomuser.me/api/portraits/men/28.jpg"
            }, {
              name: "Ben",
              email: "[email protected]",
              img: "https://randomuser.me/api/portraits/men/68.jpg"
            }];
          }
        });
      });
    </script>
  </dom-module>
</body>

plunker

Upvotes: 1

Related Questions