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

110
Visualizações
JS file load on Angular component onInit

I'm having an error while loading a flipbook library, it says Cannot set properties of null (setting 'innerHTML') and the line that is making this error:
const loadingMessageElement = document.getElementById('loading-message');
loadingMessageElement.innerHTML = 'Preparing document...';
So I think this is because the file is loading before the DOM is ready, so how can I load the file when the DOM is ready?
To clarify a little, this library is not at node_modules, is in my assets folder and I call it in my angular.json in the scripts section, I already try to import and declare the library in my ts file but I always got the error Cannot find module 'flipbook' or its corresponding type declarations.

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

0

I make it work with this function in my TS file:

ngOnInit(): void { 
    this.loadScripts();
  }

  // Method to dynamically load JavaScript
  loadScripts() {
  
    // This array contains all the files/CDNs
    const dynamicScripts = [
       'assets/flipbook/flipbook.js'
    ];
    for (let i = 0; i < dynamicScripts.length; i++) {
      const node = document.createElement('script');
      node.src = dynamicScripts[i];
      node.type = 'text/javascript';
      node.async = false;
      document.getElementsByTagName('body')[0].appendChild(node);
    }
 }
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