【发布时间】:2021-04-12 14:42:56
【问题描述】:
我有以下接口,我可以将它的参数值传递给基础组件。但是,虽然我可以毫无问题地传递字符串值,但我无法传递布尔值并遇到 "Identifier 'isDisabled' is not defined. 'CustomButton' does not contain such a member" 错误。
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 不是已知属性。我该如何解决这个问题?
【问题讨论】:
-
this.buttons: CustomButton[] = [...],试试这个,看看 ide 是否给你错误或警告
-
谢谢杰克,但我已经使用
buttons: CustomButton[];定义作为我添加到问题中。所以,我不能像你提到的那样使用它,因为它已经这样定义了。还有其他想法吗? -
问题似乎与布尔类型有关,因为其他类型在以相同方式使用时没有问题。
-
你是对的,我的错。我重新创建了你的场景,我没有收到任何错误,你使用的是哪个版本的 ionic?
-
离子是什么意思?我使用 Angular 10+
标签: javascript angular components