Ezequiel Ramiro
Ezequiel Ramiro

Reputation: 760

Ionic 4 - add external vanilla JS library into my project

I am trying to import this JS library into my Ionic 4 project: 'https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js' to use it in my angular componets. I've been looking all over the web without solution.

I tried to import into my angular.json file but is not working.

"scripts": ["https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js"]

Also I tried to import directly from my index.html but it seems is not able to read it.

Docs link

Upvotes: 0

Views: 1908

Answers (1)

Paresh Gami
Paresh Gami

Reputation: 4782

You can try like this

home.page.ts

import { Component } from '@angular/core';
declare var Mercadopago: any;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  constructor() {
    console.log(Mercadopago);
  }
}

index.html

<html>
<body>
  <app-root></app-root>
</body>
<script src="https://secure.mlstatic.com/sdk/javascript/v1/mercadopago.js"></script>
</html>

Upvotes: 1

Related Questions