Page 1 of 1

Error when lazy loading the library

Posted: Tue Jan 14, 2020 7:01 pm
by csrt
Hello. I am trying to implement the lazy loading approach, described in this post: viewtopic.php?t=57333
The approach itself works, but when loading, it keeps firing an error: stimulsoft.reports.js:43 Uncaught TypeError: Cannot redefine property: stimulsoft, which comes from here: Object.defineProperty(Number.prototype,"stimulsoft",{get:function(){return new Stimulsoft.System.StiNumber(this.valueOf())}...

To mention that when sync loading - it works just fine.
Any ideas how to fix the lazy loading error?

Re: Error when lazy loading the library

Posted: Thu Jan 16, 2020 7:59 pm
by Lech Kulikowski
Hello,

Unfortunately, we can not provide any solutions for that issue. We do not test lazy loading.

Thank you.

Re: Error when lazy loading the library

Posted: Sat Jan 18, 2020 6:14 am
by mrapi
Hello,I think you are loading the scripts more than once,in link above there is a check for that.that's our updated code that works,we added some loading time:

Code: Select all

@Injectable()
export class GeneralService {
  private stiScrpLoaded = false;
.......
  fnIsMobile(): boolean {
        return window.screen.width < 500;
    }
   ....
  public loadStimulScripts(): Promise<any> {
    return new Promise((resolve) => {
      if (!this.stiScrpLoaded) {                     //here
        this.loadScript('assets/stimulsoft.viewer.pack.js');
        this.loadScript('assets/stimulsoft.reports.pack.js');
        this.stiScrpLoaded = true;
        setTimeout(() => {
          resolve();
        }, (fnIsMobile() ? 5100 : 2500));

      } else {
        resolve();
      }
    });
}

  private loadScript(url: string) {
    const node = document.createElement('script');
    node.src = url;
    node.type = 'text/javascript';
    node.async = true;
    document.getElementsByTagName('head')[0].appendChild(node);
  }


maybe you find useful info there https://stackoverflow.com/questions/344 ... in-angular

csrt wrote: Tue Jan 14, 2020 7:01 pm ..
Any ideas how to fix the lazy loading error?

Re: Error when lazy loading the library

Posted: Sun Jan 19, 2020 9:44 pm
by Lech Kulikowski
Hello,

Thank you for the provided information.

Re: Error when lazy loading the library

Posted: Tue Jan 21, 2020 11:29 am
by csrt
mrapi wrote: Sat Jan 18, 2020 6:14 am Hello,I think you are loading the scripts more than once,in link above there is a check for that.that's our updated code that works,we added some loading time:

Code: Select all

@Injectable()
export class GeneralService {
  private stiScrpLoaded = false;
.......
  fnIsMobile(): boolean {
        return window.screen.width < 500;
    }
   ....
  public loadStimulScripts(): Promise<any> {
    return new Promise((resolve) => {
      if (!this.stiScrpLoaded) {                     //here
        this.loadScript('assets/stimulsoft.viewer.pack.js');
        this.loadScript('assets/stimulsoft.reports.pack.js');
        this.stiScrpLoaded = true;
        setTimeout(() => {
          resolve();
        }, (fnIsMobile() ? 5100 : 2500));

      } else {
        resolve();
      }
    });
}

  private loadScript(url: string) {
    const node = document.createElement('script');
    node.src = url;
    node.type = 'text/javascript';
    node.async = true;
    document.getElementsByTagName('head')[0].appendChild(node);
  }


maybe you find useful info there https://stackoverflow.com/questions/344 ... in-angular

csrt wrote: Tue Jan 14, 2020 7:01 pm ..
Any ideas how to fix the lazy loading error?
Hello, thank you for your answer - you were right

Re: Error when lazy loading the library

Posted: Wed Jan 22, 2020 6:53 am
by Andrew
Hello,

Okay, you are welcome!