Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!