简体   繁体   English

如何通过Angular 6指令将camelcase属性添加到dom元素?

[英]How can I add a camelcase attribute to a dom element via an Angular 6 directive?

It seems impossible. 似乎不可能。 Whether I use @HostBinding or elementRef.nativeElement.setAttibute(camelCaseAttribute, "true") in both cases the camelCaseAttribute becomes camelcaseattribute in the rendered dom. 在两种情况下elementRef.nativeElement.setAttibute(camelCaseAttribute, "true")无论我使用@HostBinding还是elementRef.nativeElement.setAttibute(camelCaseAttribute, "true")camelCaseAttribute都会在呈现的dom中变为camelcaseattribute

All I want to do is set ngDraggable using a directive, why is that not possible? 我要做的就是使用指令设置ngDraggable ,这为什么不可能呢? ( ngdraggable will not work) ngdraggable无效)

Thanks a lot. 非常感谢。

HTML attributes are not case sensitive. HTML属性不区分大小写。 So it doesn't matter. 所以没关系。

Attribute names for HTML elements may be written with any mix of lowercase and uppercase letters that are a case-insensitive match for the names of the attributes given in the HTML elements section of this document; HTML元素的属性名称可以用小写和大写字母的任意组合来编写,这些大小写与本文档的HTML元素部分中给出的属性名称不区分大小写; that is, attribute names are case-insensitive. 也就是说,属性名称不区分大小写。

source: http://w3c.github.io/html-reference/documents.html 来源: http : //w3c.github.io/html-reference/documents.html

If you are trying to add ngDraggable directive conditionally I think this is not a good approach. 如果您尝试有条件地添加ngDraggable指令,我认为这不是一个好方法。 Imho you should ask another question how to apply ngDraggable dynamically. 恕我直言,您应该问另一个问题,如何动态应用ngDraggable

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

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