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

186
Visualizações
Accessing external JS file's initialize function within Angular component

I am trying to add a 3rd party javascript file into my application to render some visuals on screen. I have some test code that works as a stand-alone javascript file, however migrating this into my angular application has been a bit of a headache. From my understanding, the external script loads and then I need to call the initialize function which is a global level function in the embed.js external file.

Sample (working) JS, where "myTestServer" is the location of where this 3rd party code is:

<script data-name="embed-manager"     
   src="myTestServer/embed/embed.js"></script>

   function EmbedDashboard( dashboardid ) {
            const embedManagerPromise = window.initEmbedManager({ 
                initialToken: access_token
            });

            embedManagerPromise.then((embedManager) => {
                componentConfig.dashboardId = dashboardid;  

                embedManager.createComponent( 'dashboard', componentConfig )
                    .then(dashboard => dashboard.render(
                        document.getElementById( "embedDash" ), 
                        { width: '100%', height: '100%' }
                ))
            });
        }

Using this as a starting point, I have added the embed.js script location into my angular.json file. Then in my component I have:

declare const window: any

@Component({
    selector: 'app-reports-analytics',
    templateUrl: './reports.component.html',
    styleUrls: ['./reports.component.css']
})
export class ReportsComponent implements OnInit {

    embedManagerPromise: any;

    componentConfig = {
        "dashboardId": "123456789",
        "theme":"modern",
        "interactivityProfileName":"interactive"
        },
        "editor": { "placement": "dockRight" },
        "header": { 
            "showTitle": false,
        }
    }

    constructor(
    ) { }


    embedDashboard(id) {
        this.componentConfig.dashboardId = id;

        this.embedManagerPromise = window.initEmbedManager({ 
            initialToken: '123456789123456789'
        });
    }
}

Which throws an error when trying to run the code after a button click calls embedDashboard(id)

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'src')
    at V (embed.js:1)
    at ReportsComponent.push../src/app/components/company/reporting/reports.component.ts.ReportsComponent.embedDashboard (reports.component.ts:212)
about 4 years ago · Juan Pablo Isaza
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