Search code examples
javascriptangularjspolymer

polymer equivalent to ng repeat


I am rewriting a page that is currently using an Angular 1 framework to polymer 1 (or 2). I don't know what the equivalent of ng-repeat is in polymer. This is what I have right now in Angular 1.

<div class="consultant"  ng-repeat="consultant in consultants | limitTo:i">
            <p>{{consultant.displayName}}</p>
            <p ng-if="consultant.phoneNumber != undefined" >☎ {{consultant.phoneNumber}}</p>
            <br ng-if="consultant.phoneNumber == undefined" />
            <p class="email" ng-if="consultant.email != undefined" ><span class="icon-envelope"></span><a href="mailto:{{consultant.email}}"> {{consultant.email}}</a></p>
            <br ng-if="consultant.email == undefined" />
        </div>

Solution

  • What you are looking for is dom-repeat and probably dom-if

    In your case this could look something like this:

    <template is="dom-repeat" items="[[consultants]]" as="consultant">
      <div class="consultant">
        <p>[[consultant.displayname]]</p>
        <template is="dom-if" if="[[consultant.phoneNumber]]">
          <p>☎ [[consultant.phoneNumber]]</p>
        </template>
        <template is="dom-if" if="[[!consultant.phoneNumber]]"><br></template>
        <template is="dom-if" if="[[consultant.email]]">
          <p class="email">
            <span class="icon-envelope"></span>
            <a href="mailto:[[consultant.email]]">[[consultant.email]]</a>
          </p>
        </template>
        <template is="dom-if" if="[[!consultant.email]]"><br></template>
      </div>
    </template>