繁体   English   中英

未定义标识符“X”。 'Y' 不包含这样的成员

[英]Identifier 'X' is not defined. 'Y' does not contain such a member

我有以下接口,我可以将其参数值传递给基础组件。 但是,虽然我可以毫无问题地传递字符串值,但我无法传递 boolean 值并遇到“未定义标识符'isDisabled'。'CustomButton'不包含这样的成员”错误。

export interface CustomButton {
    name: string;
    operation: string;
    tooltip: string;
    isDisabled?: boolean;
}

另一方面,我在我称之为基础组件的组件中设置了isDisabled的默认值:

buttons: CustomButton[];
isEmployeeDisabled = false; // set the value while defining variable

this.buttons = [
  {
    name: 'edit',
    tooltip: 'Edit Employee',
    operation: 'Delete',
    isDisabled: this.isEmployeeDisabled
    // isDisabled: true // if I use like this, it works fine but still gives that error
  }
];  

我找不到为什么 isDisabled 不是已知属性。 我该如何解决这个问题?

尝试使用 Stackblitz 会给我这个错误:

Type '{name: string; tooltip: string; operation: string; isDisabled: boolean; } 'is not assignable to type' CustomButton '.
Object literal may only specify known properties, and 'operation' does not exist in type 'CustomButton'.

问题是缺少interface中的operation属性。

https://stackblitz.com/edit/angular-ngclass-off-props?file=src%2Fapp%2Fapp.component.ts

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM