angular2-highcharts icon indicating copy to clipboard operation
angular2-highcharts copied to clipboard

Angular2-highcharts in a submodule

Open LucaDelBuono opened this issue 8 years ago • 4 comments

I'm having problems making angular2-highcharts work in a submodule.

If I follow the instructions provided in the readme and add the import in app.module.ts, create a simple chart in app.component.ts and have <chart [options]="options"> in app.component.html, etc... it works fine... but if I move those bits in a submodule (stats.module.ts, stats.component.ts and stats.component.html respectively), I get this error:

Unhandled Promise rejection: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart'.

What am I doing wrong?

LucaDelBuono avatar Jun 12 '17 09:06 LucaDelBuono

Never mind, managed to make it work :)

LucaDelBuono avatar Jun 12 '17 11:06 LucaDelBuono

would be great if you share your solution :)

Robouste avatar Jun 13 '17 14:06 Robouste

You can only have .forRoot calls in the root of your app, so in app.module.ts you'll have:

import { ChartModule } from 'angular2-highcharts';

import * as highcharts from 'highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';

export function highchartsFactory() {
	const hc = require('highcharts');
	const dd = require('highcharts/modules/drilldown');
	dd(hc);

	return hc;
}

@NgModule({
	.....
	imports: [
		......
		ChartModule.forRoot(require('highcharts')),
		......
	],
	exports: [
		.....
		ChartModule,
		.....
	],
	providers: [
		.....
		{
			provide: HighchartsStatic,
			useFactory: highchartsFactory
		},
		.....
	],
	.....
})

Then, in your submodule.module.ts:

import { ChartModule } from 'angular2-highcharts';

.....
@NgModule({
	imports: [
		.....
		ChartModule,
		.....
	],
})
.....

Hope that helps...

LucaDelBuono avatar Jun 13 '17 14:06 LucaDelBuono

Helped me a lot! Thanks!

kevinlimasilva1 avatar Aug 16 '17 16:08 kevinlimasilva1