【问题标题】:can't bind to '' since it isn't a known property of '' angular 2不能绑定到 '' 因为它不是 '' angular 2 的已知属性
【发布时间】:2017-10-29 00:06:42
【问题描述】:

我的 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>

错误:

无法绑定到“gridOptions”,因为它不是 'app-my-grid-application'。

任何帮助将不胜感激!

【问题讨论】:

  • @R.Richards 控制台,在运行时。这就是我使用“异常”一词的原因。

标签: javascript angular typescript


【解决方案1】:

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

public gridOptions: GridOptions;

但应该是的

@Input() gridOptions: GridOptions;

【讨论】:

  • 这是不言而喻的。所以你的意思是说我的答案是错误的?
  • Richards 的评论实际上很重要,因为我的 IDE (Web Storm) 自动从错误的地方导入了它。
  • 没关系。没问题..问题已解决或需要更多帮助?
猜你喜欢
  • 2022-08-22
  • 2018-11-30
  • 2016-12-23
  • 2017-03-18
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
  • 2016-12-18
相关资源
最近更新 更多