ravi reddy
ravi reddy

Reputation: 45

NPM initial start is failing?

I am tyring to start my angular project by doing ng s but its giving error because of some variables which are defined at window object.

var chart=window.Highcharts.chart()

Property 'Highcharts' does not exist on type 'Window'.

When i modify any file it will compile successfully automatically.

I want to ignore those errors at intial start?

Upvotes: 0

Views: 54

Answers (2)

Jacob Nelson
Jacob Nelson

Reputation: 2476

You may need to import Highcharts as given below

import * as Highcharts from 'highcharts';

Once imported, you can invoke chart method as Highcharts.chart

  ngOnInit(){
    Highcharts.chart('container', this.options);
  }

You don't need call window.Highcharts

Reference: https://www.highcharts.com/blog/post/highcharts-and-angular-7/

Upvotes: 1

Poul Kruijt
Poul Kruijt

Reputation: 71961

You should install the typings from HighCharts:

npm i -D @types/highcharts

Or update to version 7 of HighCharts which has TypeScript support included. With that version you can just import highcharts like this:

import * as Highcharts from 'highcharts';

If that doesn't work, you can also update the global window object declaration with your own properties. You should add this to either the main.ts or the polyfills.ts of your application:

declare global { interface Window { HighCharts: any; } }

Upvotes: 2

Related Questions