Angular 在角5中使用此变量
我想在我的Angular 在角5中使用此变量,angular,Angular,我想在我的中使用一个变量。。我已经这么做了,但那是很久以前的事了,我不记得怎么做了。通过谷歌或这里搜索,我没有得到任何对我有帮助的结果 这是我的代码: fieldFocused: String; (gets filled by another function) const helper = this.fieldFocused; this.[helper]Model = this.[helper]Model + this.keyboardKeyPressed; 所以我想让我的this.[h
中使用一个变量。
。我已经这么做了,但那是很久以前的事了,我不记得怎么做了。通过谷歌或这里搜索,我没有得到任何对我有帮助的结果
这是我的代码:
fieldFocused: String; (gets filled by another function)
const helper = this.fieldFocused;
this.[helper]Model = this.[helper]Model + this.keyboardKeyPressed;
所以我想让我的this.[helper]模型
被“转换”为this.usernameModel
,然后它会得到'john'的值,我该怎么做
[tl;dr]
我实际上正在研制一款覆盆子皮3,它有一个翻转的屏幕,这样就可以像一部大智能手机一样使用。没有一个屏幕上的黑板适合我的需要,所以我自己创造了一个。有三个输入,如我所说:username
、password
和ipaddress
。当用户现在单击其中一个按钮时,我将this.fieldFocused
设置为用户单击的字段,然后我希望根据最后聚焦的字段编辑模型
this.focusedInput
设置为用户名此中使用this.focusedInput
。
->此。[focusedInput]
您要查找的是属性访问器的括号符号:
this[helper+'Model']
更新代码:
fieldFocused: String; // (gets filled by another function)
const helper = this.fieldFocused;
this[helper + 'Model'] = this[helper + 'Model'] + this.keyboardKeyPressed;
这个[“用户名模型”]对不起,我编辑了我的问题
foo
并不总是username
,这只是一个例子foo
由另一个函数填充。它可以是username
password
或ipaddress
。正是我要找的!谢谢你链接这些文档