【问题标题】:Angular Uppercase/Lowercase Pipe - Why not just use css?Angular 大写/小写管道 - 为什么不只使用 css?
【发布时间】:2018-08-16 00:56:14
【问题描述】:

为什么 Angular 中存在大写/小写管道?

我能想到的任何情况下,它们都可以用于您,只需使用以下 CSS:

text-transform: uppercase|lowercase

在 css 中的文本转换不起作用或成为最佳解决方案的生产环境中使用它的任何示例?

【问题讨论】:

  • 有时您想处理数据,有时您想处理演示文稿。
  • 我想如果你希望用户能够复制大写/小写文本,爬虫可以看到它,也许将它传递给子组件输入等。

标签: angular piping


【解决方案1】:

这就是为什么:

console.log($("input").val());
input{
 text-transform: lowercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" value="EXAMPLE" />

如果你使用管道来小写,那么值将是小写的。

因此,如果您不使用输入字段或不打算从元素中提取数据,那么我会说只使用 css - 至少您只需在 1 个地方定义它(理想情况下),而必须在所有字段中显式使用管道,这对于大型应用程序来说是extensibility 的噩梦。


如果您想查看一个有效的角度示例,请检查以下问题:Using Pipes within ngModel on INPUT Elements in Angular2-View

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-17
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    相关资源
    最近更新 更多