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?
Error when lazy loading the library
-
- Posts: 6244
- Joined: Tue Mar 20, 2018 5:34 am
Re: Error when lazy loading the library
Hello,
Unfortunately, we can not provide any solutions for that issue. We do not test lazy loading.
Thank you.
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
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:
maybe you find useful info there https://stackoverflow.com/questions/344 ... in-angular
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
Last edited by mrapi on Mon Jan 20, 2020 6:33 am, edited 1 time in total.
-
- Posts: 6244
- Joined: Tue Mar 20, 2018 5:34 am
Re: Error when lazy loading the library
Hello,
Thank you for the provided information.
Thank you for the provided information.
Re: Error when lazy loading the library
Hello, thank you for your answer - you were rightmrapi 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
Re: Error when lazy loading the library
Hello,
Okay, you are welcome!
Okay, you are welcome!