Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

472
Visualizações
How to use JavaScript files in angular

I am trying to call the javascript function into the angular here is the plugin I am using "npm I global payments-3ds" of which I copied javascript files from node_modules and tried to call in my component

Below is the example :

import {
  Component,
  OnInit
} from '@angular/core';
import {
  handleInitiateAuthentication
} from './globalpayments-3ds/types/index';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  name = 'Angular';

  ngOnInit(): void {
    const status: any = "CHALLENGE_REQUIRED"
    const resp = {
      challenge: {
        encodedChallengeRequest: "abcd",
        requestUrl: "url,
      },
      challengeMandated: "MANDATED",
      dsTransactionId: "44444",
      id: "444444",
      status: status,
    };
    const windowSize: any = "WINDOWED_600X400";
    const displayMode: any = "lightbox";

    const challengeWindow = {
      windowSize: windowSize,
      displayMode: displayMode,
    };
    handleInitiateAuthentication(resp, challengeWindow)
  }
}

I am trying to call the handleInitiateAuthentication() which is giving me the below error enter image description here

Here is the file structure

enter image description here

from index.d.ts i am calling the handleInitiateAuthentication() function

Here is Stackblitz code for the same

https://stackblitz.com/edit/angular-vodezz?file=src%2Fapp%2Fapp.component.ts

Please help I never used the js function in angular I tried to add in assets not worked I have tried to create an angular library and add the js files in it and update the package, by converting the file to .tgz but nothing working it showing always the same error,

Why am I doing is I have to update one of the files from node_modules, basically I wanna change files from node modules which is why i copied those files locally

this is also giving error enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You don't need to import a library like that. First of all install the library to your project:

npm i globalpayments-3ds --save

then in your ts file:

import { handleInitiateAuthentication } from 'globalpayments-3ds';

see this stackblitz

about 4 years ago · Juan Pablo Isaza Relatório

0

You have to import directly js file.

// @ts-ignore 
    import { handleInitiateAuthentication } from './globalpayments-3ds/globalpayments-3ds.esm.js';

For error about module, it's because you have to define type of your module in TypeScript. You can directly use // @ts-ignore.

See this stackblitz : https://stackblitz.com/edit/angular-xz4kmp?file=src%2Fapp%2Fapp.component.ts

about 4 years ago · Juan Pablo Isaza Relatório

0

The recommended way to make your own modified versions from open source libraries is to fork them and build your own versions.

Also note that you must take into account the license of that NPM package which in the case of https://github.com/globalpayments/globalpayments-js is GPL-v2, so if you will use it for commercial purposes you must follow the agreement. Check this branch: GNU General Public License (v2): can a company use the licensed software for free?.

Taking a look to your Stackblitz code, you may notice that there are several JS versions of the same module in src/app/global-payments-3ds/ folder:

  • globalpayments-3ds.js (CommonJS, used in Node environments).
  • globalpayments-3ds.min.js (CommonJS minified).
  • globalpayments-3ds.js.map (CommonJS minified map file to reference during debugging).
  • globalpayments-3ds.esm.js (ESM, ECMA Standard Module).
  • ...

To use an external JS Module in an Angular App, as it is JavaScript and not TypeScript, you must tell TypeScript Compiler that you want to allow JS modules by enabling allowJS: true in tsconfig.ts file at the root of the project.

After that you should be be able to import the ESM version (globalpayments-3ds.esm.js) in your Angular App, or if you want to use the CommonJS version, you can also enable esModuleInterop: true in tsconfig.ts to allow importing CommonJS/AMD/UMD JS modules in your project, like globalpayments-3ds.js.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda