I have a legacy script that I need to include in my angular application.
The thing about this script is that it relates to a specific component, and it has to be loaded only after the view of the component is loaded.
As for today, I succeeded to include it on OnInit function but sometimes (not always for some reason) the CLI throws an error about it.

import { Component, OnInit } from '@angular/core';

  selector: 'app-player-page',
  templateUrl: './player-page.component.html',
  styleUrls: ['./player-page.component.scss']
export class PlayerPageComponent implements OnInit {
  public itemId: string;
  constructor() {}

  ngOnInit() {
    //We loading the player srcript on after view is loaded


The script assumes that elements in the UI exists and it searches them by the id.
When adding it on top of the page, it doesn’t work.
What is the best way to achieve the desired behavior?