简体   繁体   English

{{}}中的字符串作为插值代码

[英]String inside {{ }} as Interpolation Code

The FormControlNames of my elements are generated dynamicly this way: id{{foo.foo_id}}{{bar.bar_id}}{{bob.bob_id}} 我的元素的FormControlNames是通过以下方式动态生成的: id{{foo.foo_id}}{{bar.bar_id}}{{bob.bob_id}}

The result is something like id137 . 结果是类似id137东西。

When I now use {{form.controls.id137.status}} , in the HTML , I get VALID / INVALID like it should. 当我现在使用{{form.controls.id137.status}} ,在HTML ,我会像应该的那样得到VALID / INVALID

But when I do {{'form.controls.id' + foo.foo_id + bar.bar_id + bob.bob_id + '.status'}} I just get the line form.controls.id137.status on my page as a string, but it is not actually run. 但是当我执行{{'form.controls.id' + foo.foo_id + bar.bar_id + bob.bob_id + '.status'}}我只是在页面form.controls.id137.status行作为字符串,但实际上并未运行。

How can I make Angular run this string? 如何使Angular运行此字符串?

You are creating a string when you add quotes around 'form.controls.id' and '.status' 当您在“ form.controls.id”和“ .status”周围添加引号时,您正在创建一个字符串

Try something like: 尝试类似的方法:

{{ form.get('id' + foo.foo_id + bar.bar_id + bob.bob_id)?.status }}

try 尝试

{{ form.get('id'+foo.foo_id + '' + bar.bar_id + '' + bob.bob_id)?.status }}

or 要么

{{ form.controls['id'+foo.foo_id + '' + bar.bar_id + '' + bob.bob_id]?.status }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM