Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7c4392

Browse files
committed
Adding plotly-via-window.module
1 parent 0c5e59b commit b7c4392

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

projects/demo_app/src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PlotlyViaCDNModule } from 'projects/plotly/src/lib/plotly-via-cdn.modul
77

88

99
import { AppComponent } from './app.component';
10+
import { PlotlyViaWindowModule } from 'projects/plotly/src/lib/plotly-via-window.module';
1011

1112

1213
@NgModule({
@@ -16,7 +17,8 @@ import { AppComponent } from './app.component';
1617
imports: [
1718
BrowserModule,
1819
// PlotlyModule.forRoot(PlotlyJS),
19-
PlotlyViaCDNModule.forRoot({version: '3.0.1'}),
20+
// PlotlyViaCDNModule.forRoot({version: '3.0.1'}),
21+
PlotlyViaWindowModule,
2022
],
2123
providers: [],
2224
bootstrap: [AppComponent]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NgModule } from '@angular/core';
2+
import { PlotlyService } from './plotly.service';
3+
import { PlotlyComponent } from './plotly.component';
4+
5+
6+
@NgModule({
7+
imports: [PlotlyComponent],
8+
providers: [PlotlyService],
9+
exports: [PlotlyComponent],
10+
})
11+
export class PlotlyViaWindowModule {
12+
constructor() {
13+
const plotly = (window as any).Plotly;
14+
15+
if (typeof plotly === 'undefined') {
16+
throw new Error(`Plotly object not found on window.`);
17+
}
18+
19+
PlotlyService.setPlotly(plotly);
20+
}
21+
}

0 commit comments

Comments
 (0)