Angular 8 - Не удается прочитать свойство 'appendChild' со значением null в ZoneDelegate.invokeTask - PullRequest
0 голосов
/ 15 апреля 2020

Angular 8 - Не удается прочитать свойство 'appendChild' с нулевым значением в ZoneDelegate.invokeTask

myfile. html

<div id="loaddynamiccss"></div>

mytypescriptfile.ts

ngOnInit() {
    this.LoadPaceTheme('../../../@theme/styles/pace.theme.scss');
  }

 LoadPaceTheme(cssFile: string) {
    /* Loader Pace-Theme for Header */
    //var headE1 = this.document.getElementById('loaddynamiccss');
    var headE1 = <HTMLElement>document.getElementById("loaddynamiccss");
    const newLinkEl = this.document.createElement('link');
    newLinkEl.rel = 'stylesheet';
    newLinkEl.href = cssFile;
    console.log(newLinkEl);
    setTimeout(() => {
      headE1.appendChild(newLinkEl);
    }, 2000);
  }

Нужна помощь в этом ---- Любая идея, почему его предоставление Не удается прочитать свойство 'appendChild'?

1 Ответ

0 голосов
/ 15 апреля 2020

Изменить

const newLinkEl = this.document.createElement('link');

на

const newLinkEl = document.createElement('link');
...