Angular 10 根据用户输入显示对象值 属性

Angular 10 display object value as per user input property

考虑一个 对象 emp 具有属性 nameage.

根据用户在文本框中输入姓名或年龄,我需要显示对象中的值。

一般我们可以显示为{{emp.name}}{{emp.age}} 但就我而言,emp 的 属性 是 dynamic.

For example: If an input text is x then the emp property should have x in it. like {{emp.x}}

如何实现?

Property name should be taken from the user input. No condition or logical things.

关于 ngmodel 也一样。

提前致谢

如果要确定动态 属性 的值,您应该这样做:

{{ emp['x'] }}

方括号符号查找对象的属性,其中包含名称。