1
votes

I have this code in HTML:

<ag-grid-angular [gridOptions]="gridOptions"></ag-grid-angular>

code in Component:

import {GridOptions} from 'ag-grid'; 
...

export class SampleComponent{
   gridOptions: GridOptions;
}
...

app.module.ts:

import {NgModule} from "@angular/core";
import {AgGridModule} from "ag-grid-angular/main";
import {AppComponent} from "./app.component";
...

@NgModule({
    declarations: [...],
    imports: [
        ...
        AgGridModule.withComponents([])
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule {
}

What can be the source for the error that I get? Here is the full error:

Error: Uncaught (in promise): Error: Template parse errors: Can't bind to 'gridOptions' since it isn't a known property of 'ag-grid-angular'.

  1. If 'ag-grid-angular' is an Angular component and it has 'gridOptions' input, then verify that it is part of this module.
  2. If 'ag-grid-angular' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
2
can you post your app.module.ts - Sajeetharan
Possible duplicate of (stackoverflow.com/a/44238887/9775003) - Sanoj_V
@Sanoj_V The solution is that question does not solve my problem. I already have AgGridModule.withComponents([]) in imports. - matchifang
@Sajeetharan Yes, I have added the app.module.ts - matchifang
I don't know whether this will help, but in my class that uses ag-grid I have the following import: import { AgGridNg2 } from 'ag-grid-angular'; (I don't have the import of AgGridModule). - Andy King

2 Answers

0
votes

Try to initiatlize gridOptions as follows and see

constructor() {
    this.gridOptions = <GridOptions>{};
    this.columnDefinitions = [

    ];

    this.gridOptions = {
      columnDefs: this.columnDefinitions,
      enableFilter: true,
      enableSorting: true,
      pagination: true
    };

    this.rowSelection = 'single';
  }

EDIT

Your actual issue is here, Change

From

<ag-grid-angular [gridOptions]="gridOptions"></ag-grig-angular>

To

<ag-grid-angular [gridOptions]="gridOptions"></ag-grid-angular>
0
votes

You can create a grid without gridOptions as well in your cae. Please find below the complete code:-

<ag-grid-angular style="width: 500px;height: 200px;" class="ag-theme-balham" [animateRows]="true" [columnDefs]="columnDefs" [enableSorting]="true" [enableFilter]="true" (gridReady)="OnGridReady($event)">