[英]how to dynamically access template reference variables (symbol: #) defined in the angular.html
我无法访问模板引用变量#interface if this.activeTab = 'interface';
// parent.html
<button type="button" [disabled]="activeTab.revertDisabled"></button>
<interface-settings #interface></interface-settings>
<car #car></car>
// parent.ts
this.activeTab = 'interface';
//child.ts (interface-settings.ts)
this.revertDisabled = true;
但是如果我将其更改为以下内容,则它可以访问#interface。
<button type="button" [disabled]="interface.revertDisabled"></button>
有没有一种方法可以动态访问“this.activeTab”的值?
我尝试了以下但不起作用
<button type="button" [disabled]="[activeTab].revertDisabled"></button>
如何使用 getter
get revertDisabled(){
return yourActivetabl.get.somehow.your.value;
}
和
<button type="button" [disabled]="revertDisabled"></button>
如果您还需要获取接口组件的实例,请使用
@ViewChildren("interface") //this is the #innterface value
instances:QueryList(InterfaceClass);
您不能使用activeTab
作为参考,因为activeTab
是一个字符串。 相反,您应该像以前一样使用括号表示法,以便您可以引用 class 成员,它的名称是activeTab
的值。
将this
添加到括号前:
<button type="button" [disabled]="this[activeTab].revertDisabled"></button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.