我正在尝试根据传递的值设置true或false,但不能在angular 8中使用。如果有人知道,请帮助解决这个问题。
app.component.ts:
this.main = {
power: false,
electrical: false,
wire: false,
current: false
}
testing(flag){
this.main[flag]=true;
}
testing(wire);
假设您在组件类中,则在调用wire
时未定义testing
。它必须是一个字符串才能工作。另外,您使用的是this
错误。试试:
main = {
power: false,
electrical: false,
wire: false,
current: false
}
testing(flag){
this.main[flag] = true;
}
然后在同一组件的另一个函数内的某个地方:
this.testing("wire");
main={
power:false,
electrical:false,
wire:false,
current:false
}
testing(flag, value){
this.main[flag]=value;
}
this.testing('wire', flase);
请尝试这样