Skip to content

Commit

Permalink
fix service injection
Browse files Browse the repository at this point in the history
  • Loading branch information
gevgeny committed Feb 11, 2017
1 parent 0342471 commit ed92928
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 45 deletions.
6 changes: 5 additions & 1 deletion dist/HighchartsService.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export declare class HighchartsStatic {
}
export declare class HighchartsService {
getHighchartsStatic(): Object;
_highchartsStatice: HighchartsStatic;
constructor(highchartsStatic: HighchartsStatic);
getHighchartsStatic(): HighchartsStatic;
}
21 changes: 17 additions & 4 deletions dist/HighchartsService.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/HighchartsService.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/HighchartsService.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"HighchartsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"getHighchartsStatic":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"HighchartsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"getHighchartsStatic":[{"__symbolic":"method"}]}}}}]
[{"__symbolic":"module","version":3,"metadata":{"HighchartsStatic":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"HighchartsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"HighchartsStatic"}]}],"getHighchartsStatic":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"HighchartsStatic":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}]},"HighchartsService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"HighchartsStatic"}]}],"getHighchartsStatic":[{"__symbolic":"method"}]}}}}]
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ChartSeriesComponent } from './ChartSeriesComponent';
import { ChartPointComponent } from './ChartPointComponent';
import { ChartXAxisComponent } from './ChartXAxisComponent';
import { ChartYAxisComponent } from './ChartYAxisComponent';
export declare function getHighchartsStatic(): Object;
import { HighchartsStatic } from './HighchartsService';
export declare class ChartModule {
static forRoot(highchartsStatic: Object, ...highchartsModules: any[]): ModuleWithProviders;
static forRoot(highchartsStatic: HighchartsStatic, ...highchartsModules: Array<Function>): ModuleWithProviders;
}
export { ChartComponent, ChartSeriesComponent, ChartPointComponent, ChartXAxisComponent, ChartYAxisComponent };
23 changes: 12 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"getHighchartsStatic":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"error","message":"Reference to a local symbol","line":8,"character":4,"context":{"name":"_highchartsStatic"}}},"ChartModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]],"exports":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]]}]}]},"ChartComponent":{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},"ChartSeriesComponent":{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},"ChartPointComponent":{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},"ChartXAxisComponent":{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},"ChartYAxisComponent":{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}}},{"__symbolic":"module","version":1,"metadata":{"getHighchartsStatic":{"__symbolic":"function","parameters":[],"value":{"__symbolic":"error","message":"Reference to a local symbol","line":8,"character":4,"context":{"name":"_highchartsStatic"}}},"ChartModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]],"exports":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]]}]}]},"ChartComponent":{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},"ChartSeriesComponent":{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},"ChartPointComponent":{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},"ChartXAxisComponent":{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},"ChartYAxisComponent":{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}}}]
[{"__symbolic":"module","version":3,"metadata":{"ChartModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]],"exports":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]]}]}]},"ChartComponent":{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},"ChartSeriesComponent":{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},"ChartPointComponent":{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},"ChartXAxisComponent":{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},"ChartYAxisComponent":{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}}},{"__symbolic":"module","version":1,"metadata":{"ChartModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]],"exports":[[{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}]]}]}]},"ChartComponent":{"__symbolic":"reference","module":"./ChartComponent","name":"ChartComponent"},"ChartSeriesComponent":{"__symbolic":"reference","module":"./ChartSeriesComponent","name":"ChartSeriesComponent"},"ChartPointComponent":{"__symbolic":"reference","module":"./ChartPointComponent","name":"ChartPointComponent"},"ChartXAxisComponent":{"__symbolic":"reference","module":"./ChartXAxisComponent","name":"ChartXAxisComponent"},"ChartYAxisComponent":{"__symbolic":"reference","module":"./ChartYAxisComponent","name":"ChartYAxisComponent"}}}]
2 changes: 1 addition & 1 deletion examples/angular-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2",
"angular2-highcharts": "git:https://github.com/gevgeny/angular2-highcharts.git#a1452f7777fe6f0fd38c78aece21430812f9f289"
"angular2-highcharts": "git:https://github.com/gevgeny/angular2-highcharts.git#034247135c96165ce7c6415e3c07375a179e914e"
},
"devDependencies": {
"@angular/cli": "1.0.0-beta.31",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular-cli/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppComponent } from './app.component';
import { ChartModule } from 'angular2-highcharts';

const highstock: Object = require('highcharts/highstock');
const chartModule: any = ChartModule.init(highstock);
const chartModule: any = ChartModule.forRoot(highstock);

@NgModule({
declarations: [
Expand Down
2 changes: 1 addition & 1 deletion examples/webpack/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ declare var require: any;
JsonpModule,
ChartModule.forRoot(
require('../../../node_modules/highcharts/highstock.src'),
require('../../../node_modules/highcharts/highcharts-3d.js')
require('../../../node_modules/highcharts/highcharts-3d.src.js')
)
],
declarations: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-highcharts",
"version": "0.5.1",
"version": "0.5.2",
"description": "Highcharts for your Angular2 project",
"scripts": {
"watch": "ntsc -w",
Expand Down
14 changes: 12 additions & 2 deletions src/HighchartsService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { getHighchartsStatic } from './index';
import { Injectable } from '@angular/core';

@Injectable()
export class HighchartsStatic {

}

@Injectable()
export class HighchartsService {
_highchartsStatice: HighchartsStatic

constructor(highchartsStatic: HighchartsStatic) {
this._highchartsStatice = highchartsStatic;
}

getHighchartsStatic() {
return getHighchartsStatic();
return this._highchartsStatice;
}
}
30 changes: 13 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { ChartSeriesComponent } from './ChartSeriesComponent';
import { ChartPointComponent } from './ChartPointComponent';
import { ChartXAxisComponent } from './ChartXAxisComponent';
import { ChartYAxisComponent } from './ChartYAxisComponent';

let _highchartsStatic: Object;
import { HighchartsStatic } from './HighchartsService'

const CHART_DIRECTIVES: any[] = [
ChartComponent,
Expand All @@ -16,26 +15,23 @@ const CHART_DIRECTIVES: any[] = [
ChartYAxisComponent
];

export function getHighchartsStatic() {
return _highchartsStatic;
}

@NgModule({ declarations: [CHART_DIRECTIVES], exports: [CHART_DIRECTIVES] })
@NgModule({
declarations: [CHART_DIRECTIVES],
exports: [CHART_DIRECTIVES]
})
export class ChartModule {
static forRoot(highchartsStatic: Object, ...highchartsModules): ModuleWithProviders {
if (!highchartsStatic) {
throw new Error('Highcharts module cannot be empty.')
}

// Save Highcharts/Highstock/Highmaps static
_highchartsStatic = highchartsStatic;

static forRoot(highchartsStatic: HighchartsStatic, ...highchartsModules: Array<Function>): ModuleWithProviders {
// Plug highcharts modules
highchartsModules.forEach((module) => {
module(_highchartsStatic)
module(highchartsStatic)
});

return { ngModule: ChartModule }
return {
ngModule: ChartModule,
providers: [
{ provide: HighchartsStatic, useValue: highchartsStatic }
]
}
}
}

Expand Down

0 comments on commit ed92928

Please sign in to comment.