[英]Angular2 Directive - selector with multiple ids
I'm implementing a custom directive in Angular 2, directive for form validation, and in many places I see that in the directive definition the selector property is associated with multiple ids - for example: 我正在Angular 2中实现一个自定义指令,用于表单验证,在许多地方我看到在指令定义中,selector属性与多个id相关联 - 例如:
@Directive({
selector: '[my-custom-validator][ngModel]'
})
What does the multiple '[...]' (brackets) selection mean? 多个'[...]'(括号)选择意味着什么?
As in CSS, the selector [attr]
matches elements that have an attribute named attr
. 与在CSS中一样,selector
[attr]
匹配具有名为attr
的属性的元素。 When multiple attribute selectors are chained together, all the attributes must exist on the element. 当多个属性选择器链接在一起时,元素上必须存在所有属性。
Note: Unlike CSS, Angular ignores any [...]
or [(...)]
binding brackets on the target attribute when it performs the match. 注意:与CSS不同,Angular在执行匹配时会忽略target属性上的任何
[...]
或[(...)]
绑定括号。
Thus, the selector [my-custom-validate][ngModel]
matches elements that have both a my‑custom‑validate
attribute and an ngModel
attribute (including [ngModel]
and [(ngModel)]
). 因此,selector
[my-custom-validate][ngModel]
匹配同时具有my‑custom‑validate
属性和ngModel
属性(包括[ngModel]
和[(ngModel)]
)的[(ngModel)]
。 For example, the selector matches 例如,选择器匹配
<input type="text" name="username" my-custom-validate [(ngModel)]="model.username">
but not 但不是
<input type="text" name="username" my-custom-validate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.