Jose Pedro Dava
Jose Pedro Dava

Reputation: 63

Import js library in polymer 2.0

I'm facing an issue I want to know how can I import an external javascript "library/ file" to my polymer project. I want to use the htmlToPdf.js library in polymer. but I can't call the functions on the htmlToPdf.js.

Upvotes: 1

Views: 1460

Answers (2)

Hyyan Abo Fakher
Hyyan Abo Fakher

Reputation: 3537

If you are going to reuse the library in different components, then it is better to create an import component

<!-- htmlToPdf-import.html -->
<script src="../htmlToPdf/htmlToPdf.js" charset="utf-8"></script>

<!-- my-component.html -->

<link rel="import" href="./htmlToPdf-import.html">

<dom-module id="my-component">
  <template>
  </template>

  <script>
    class MyComponent extends Polymer.Element {
      static get is() {
        return 'my-component';
      }
    }

    window.customElements.define(MyComponent.is, MyComponent);
  </script>
</dom-module>

Upvotes: 1

Tsvetan Ganev
Tsvetan Ganev

Reputation: 8856

You can import it in a Polymer component using a regular <script> tag.

Upvotes: 0

Related Questions