简体   繁体   English

Angular 样式绑定变量名称转换为 kebab-case

[英]Angular style binding variable name get converted to kebab-case

I need to bind custom css variable using Angular style binding.我需要使用 Angular 样式绑定来绑定自定义 css 变量。 When I'm using variable with camelCase, it get converted to kebab-case automatically, and I don't know why.当我将变量与 camelCase 一起使用时,它会自动转换为 kebab-case,我不知道为什么。

It' seems that this is not a default behaviour of Angular. Because this does not happened on new created Angular project, but only occured in this template I'm using (Vuexy): https://pixinvent.com/demo/vuexy-angular-admin-dashboard-template/landing/这似乎不是 Angular 的默认行为。因为这不会发生在新创建的 Angular 项目中,而只会发生在我正在使用的模板中(Vuexy): https://pixinvent.com/demo/vuexy- angular-admin-dashboard-template/着陆/

This is how I add my css variable:这就是我添加 css 变量的方式:

<div class="line-clamp" [style.--lineClamp]="2">
    {{ data }}
</div>

And this is the result I get:这是我得到的结果:

--line-clamp: 2

.line-clamp {
    --lineClamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--lineClamp);
    text-overflow: ellipsis;
    overflow: hidden;

As you can see the variable name is auto convert from camelCase to kebab-case.如您所见,变量名自动从驼峰命名法转换为烤肉串命名法。 Of course to quickly solve the problem I can just use kebab-case, but I want to know what is the cause, anyone has the same experience?当然为了快速解决问题我可以使用kebab-case,但我想知道是什么原因,有没有人有同样的经历?

After some researches, found that it was a bug.经过一些研究,发现这是一个错误。

https://github.com/angular/angular/issues/41364 https://github.com/angular/angular/issues/41364

And I solve this issue by updating my project version, from version 11.2.1 to latest version of 11我通过更新我的项目版本来解决这个问题,从 11.2.1 版本到最新版本 11

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

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