Originally I was having issues with this package using Angular SSR as I was getting this error on import Window is not defined
However, you can mock this in server.ts
via the following:
JavaScript
x
4
1
const MockBrowser = require('mock-browser').mocks.MockBrowser;
2
const mock = new MockBrowser();
3
global.window = mock.getWindow();
4
I’m now getting an error as stated in the title, SVG is not defined. IS there any way to mock this?
I believe it uses https://github.com/svgdotjs/
under the hood
Thanks
Advertisement
Answer
Using ng-apexcharts
, I still get the ReferenceError: SVG is not defined
error. So this is what I tried and seems to be working.
I’m NOT importing
NgApexchartsModule
template.html
JavaScript
1
2
1
<div id="chart" *ngIf="isBrowser"></div>
2
- component.ts
JavaScript
1
12
12
1
constructor(@Inject(PLATFORM_ID) platformId: object) {
2
this.isBrowser = isPlatformBrowser(platformId);
3
}
4
5
6
7
if (this.isBrowser) {
8
const ApexCharts = require('apexcharts');
9
const chart = new ApexCharts(document.querySelector('#chart'), this.options);
10
chart.render();
11
}
12