Search code examples
javascriptangularjsangularhighchartsangular2-highcharts

Error: Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart'


I have the following component

import { Component, OnInit, Input } from '@angular/core';
import { Observable } from 'rxjs/Rx';

@Component({
    selector: 'chart',
    templateUrl: 'app/comps/chart.html',
    providers: [],
})
export class ChartComp {

    constructor() {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
    }
    options: Object;
}

and module file

import { ChartModule } from 'angular2-highcharts';

@NgModule({
    imports: [ChartModule.forRoot(require('highcharts'))],

declarations: [Chart],
exports: [Chart]})

export class ModuleFile {
....
}

and html file

<chart [options]="options"></chart>

Then I have an example page, which implements this component

import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
    selector: 'example-chart',
    templateUrl:'app/comps/chart/example-chart.html',
    providers: [],
})


export class ExampleChart{

    constructor(

    ) {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
    }
    options: Object;
}

and html

<chart [options]="options"></chart>

where options is the configuration passed to the html. But not sure why I am getting this weird error

EXCEPTION: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'options' since it isn't a known property of 'chart'.
1. If 'chart' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'chart' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

I tried adding @Input for the options. Then I get a DI error. Any idea guys? Thanks in advance.


Solution

  • You need to make it an input to be able to bind to it using property-binding:

    @Input()
    options: Object;