2017-05-28 85 views
0

我在Angular 2项目中遇到异常,并且不明白为什么。无法绑定到'',因为它不是已知属性''angular 2

这是我的代码:

TS:

import {Component} from "@angular/core"; 
import {GridOptions} from "ag-grid"; 
import {RedComponentComponent} from "../red-component/red-component.component"; 

@Component({ 
    selector: 'app-my-grid-application', 
    templateUrl: './my-grid-application.component.html' 
}) 
export class MyGridApplicationComponent { 
    public gridOptions: GridOptions; 

    constructor() { 
    this.gridOptions = {}; 
    this.gridOptions.columnDefs = [ 
     { 
     headerName: "ID", 
     field: "id", 
     width: 100 
     }, 
     { 
     headerName: "Value", 
     field: "value", 
     cellRendererFramework: RedComponentComponent, 
     width: 100 
     }, 

    ]; 
    this.gridOptions.rowData = [ 
     {id: 5, value: 10}, 
     {id: 10, value: 15}, 
     {id: 15, value: 20} 
    ] 
    } 
} 

HTML:

<div style="width: 200px;"> 
    <app-my-grid-application #agGrid style="width: 100%; height: 200px;" class="ag-fresh" 
        [gridOptions]="gridOptions"> 
    </app-my-grid-application> 
</div> 

错误:

Can't bind to 'gridOptions' since it isn't a known property of 'app-my-grid-application'.

任何帮助将深刻地感谢!

+0

@ R.Richards控制台,在运行时。这就是我使用“例外”这个词的原因。 – Alon

回答

2

在你的组件,这是一个属性

public gridOptions: GridOptions; 

但应

@Input() gridOptions: GridOptions; 
+1

这不言而喻。所以你的意思是说我的答案是错误的? – Aravind

+0

这是由IDE处理的,不用担心。给予好评! – Aravind

+0

Richards的评论实际上很重要,因为我的IDE(Web Storm)已经从错误的地方自动导入它。 – Alon

相关问题