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
    设置为用户名
  • 他按键盘上的“a”键调用一个函数
  • 根据聚焦字段的不同,我必须编辑模型,这就是为什么我需要在另一个
    此中使用
    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
    。正是我要找的!谢谢你链接这些文档