角度-如何检查组件标签上是否具有特定属性? [英] Angular - How to check if a component tag has specific attribute on it?
本文介绍了角度-如何检查组件标签上是否具有特定属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过以下方式使用 app-somecomponent
<app-somecomponent required></app-somecomponent>
如何检查 app-somecomponent
app-somecomponent.component.ts
中的必需
属性是什么?我不不要为必需属性使用任何值(例如,不允许使用 [required] = true
)
How do I check if app-somecomponent
has the required
attribute from the app-somecomponent.component.ts
? I don't wan't to use any value for the required attribute (so [required]="true"
, for instance is not allowed)
关于- hasAttribute( )?- $ attr
在较新的Angular版本中不可用。
About the - AngularJS equivalent for hasAttribute()? - the $attr
is not available in the newer versions of Angular.
推荐答案
尝试
@Input() required;
isRequired: boolean;
ngOnInit() {
this.isRequired = this.required !== undefined;
}
这篇关于角度-如何检查组件标签上是否具有特定属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文