简体   繁体   English

Angular:模板组件是否区分大小写

[英]Angular: Are template components case sensitive

This is a follow up question from an earlier post. 这是先前帖子中的后续问题。 In this post I ran into a problem where I could not get the value from a <select> element. 这篇文章中,我遇到了一个问题,我无法从<select>元素获取值。 The solution turned out to be embarrassingly simple. 事实证明,该解决方案非常简单。 Use lowercase <select> in the Angular template instead of uppercase <SELECT> . 在Angular模板中使用小写的<select>而不是大写的<SELECT>

在此处输入图片说明

We all know HTML is case insensitive, which leads me to my question. 我们都知道HTML不区分大小写,这使我想到了问题。 Why was I unable to get the value of the select when the element was <SELECT> , are Angular templates case sensitive? 为什么当元素为<SELECT>时我无法获取select的值, Angular模板区分大小写?

When I inspect the element in the DOM regardless of whether I used <SELECT> or <select> , the element is always rendered in lowercase. 当我检查DOM中的元素时,无论使用的是<SELECT>还是<select>该元素始终以小写形式呈现。 Which from my understanding is expected standard browser behavior. 根据我的理解,这是预期的标准浏览器行为。 This further leads to my suspicion that the behavior I experienced is a result of something Angular is doing. 这进一步导致我怀疑我的行为是Angular正在做的结果。

I've scoured the internet trying to find an explanation for this, but have been unable to find an explanation. 我搜寻了互联网,试图为此找到一个解释,但一直无法找到一个解释。 Almost immediately after asking the original question, user JBNizet, was able to point out my mistake in the HTML. 在询问原始问题之后,用户JBNizet几乎立即就能指出我在HTML中的错误。 It is that level of insight and understanding of the relationship between HTML templates and Angular I am trying to gain. 我试图获得的正是对HTML模板与Angular之间关系的见识和理解水平。

Are template components case sensitive? 模板组件是否区分大小写?

Yes, the templates are case-sensitive in Angular. 是的,模板在Angular中区分大小写。 You have to write ngIf , for example, in order to trigger parsing it as a directive with the selector [ngIf] . 例如,您必须编写ngIf才能触发使用选择器[ngIf]将其解析为指令。 ngif or NGIF would not work. ngifNGIF无法使用。

Using SELECT works as expected wihout a problem. 使用SELECT可以正常工作而不会出现问题。 The culprit is the control value accessor for the select element, which has a selector specified as something like select[formControlName] , which does not match <SELECT formControlName=foo> . 罪魁祸首是select元素的控制值访问器,该元素具有一个选择器,该选择器指定为select[formControlName]类的select[formControlName]器,该选择器与<SELECT formControlName=foo>不匹配。

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

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