我正在尝试将值分配给变量,但无法正常工作。如果有人知道,请帮助寻找解决方案。
我的代码:
app.component.ts:
public power:any;
public ice:any;
public cake:any;
changeValue(prop,val){
this.[prop]=val;
console.log(this.[prop]);
}
this.changeValue("power","124525");
this.changeValue("ice","125658");
this.changeValue("cake","122568");
答案 0 :(得分:0)
public power:any;
public ice:any;
public cake:any;
changeValue(prop,val){
this[prop]=val;
console.log(this[prop]);
}
this.changeValue("power","124525");
this.changeValue("ice","125658");
this.changeValue("cake","122568");