【问题标题】:Is this notice "Identifier 'gridOptions' refers to a private member of the componentAngular" telling me that I am not following coding best practices?这个通知“标识符'gridOptions'指的是componentAngular的私有成员”是否告诉我我没有遵循编码最佳实践?
【发布时间】:2019-09-06 15:56:58
【问题描述】:

我正在使用 ag-grid 作为框架来构建我的网格(显然)。
我遵循了一个简单的教程。所以这是到目前为止的代码,

typography.component.html

typography.component.ts

import {Component} from "@angular/core";
import {GridOptions} from "ag-grid-community";


@Component({
    selector: 'typography-cmp',
    moduleId: module.id,
    templateUrl: 'typography.component.html'
})

export class TypographyComponent {
    private gridOptions: GridOptions;

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

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

这非常有效。但是,您可能已经在 html 文件中注意到:

网格选项

以红色为底色。 这就是为什么:

标识符'gridOptions'指的是组件的私有成员

这是可以理解的。我正在关注官方教程。我想知道代码是否违反了任何编码规则或最佳实践?
谢谢。

【问题讨论】:

    标签: html node.js angular typescript ag-grid


    【解决方案1】:

    当您在模板中使用gridOptions 时,不应将其声明为private 变量。

    更多参考:Angular2 - should private variables be accessible in the template?

    另一个帖子仍在 GitHub 上打开,但您会得到更多关于此的想法:Better offline compiler error when accessing private properties

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      相关资源
      最近更新 更多