Polymer 2.0: iron-icon not working in Starter kit

577 views Asked by At

I am newbie in Polymer projects, I have installed polymer 2.0 starterkit, everything works fine except iron-icon. It doesn't display icon when i run project.

    <!-- Load the Polymer.Element base class -->
    <link rel="import" href="../bower_components/polymer/polymer-element.html">

    <script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="../bower_components/iron-icon/iron-icon.html">
    <link rel="import" href="../bower_components/iron-iconset-svg/iron-iconset-svg.html">

    <dom-module id="my-iconsset-view">
      <!-- Defines the element's style and local DOM -->
      <template>
        <style>
          :host {
            display: block;

            padding: 16px;
          }
        </style>

        <h1>My Iconsc</h1>

        <iron-icon icon="icon:menu"></iron-icon>
        <iron-icon icon="input"></iron-icon>


      </template>
      <script>
        // Your new element extends the Polymer.Element base class
        class MyIconssetView extends Polymer.Element {
          static get is() { return 'my-iconsset-view'; }
        }
        //Now, register your new custom element so the browser can use it
        customElements.define(MyIconssetView.is, MyIconssetView);
      </script>
    </dom-module>
1

There are 1 answers

2
Ofisora On BEST ANSWER

Import <link rel="import" href="../bower_components/iron-icons/iron-icons.html"> instead of just iron-icon.

Also, you don't have to mention icon="icon:menu", just icon="menu" is fine, unless you have defined your own iconset and named as 'icon'.

The iron-icon element is used for displaying an icon.

iron-icons is a utility import that includes the definition for the iron-icon element, iron-iconset-svg element, as well as an import for the default icon set.