如何为角度7中的变量分配值

时间:2019-12-05 17:41:56

标签: javascript typescript angular7

我正在尝试将值分配给变量,但无法正常工作。如果有人知道,请帮助寻找解决方案。

我的代码:

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");

1 个答案:

答案 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");