Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Uppercase/Lowercase Pipe - Why not just use css?

Tags:

angular

piping

Why do the uppercase/lowercase pipes exist in Angular?

Any situation I can think of that they would be used for you could just use the below CSS instead:

text-transform: uppercase|lowercase

Any examples for using this in pipe in production where the text-transform in css wouldn't work or be the best solution?

like image 764
Tony Scialo Avatar asked Mar 07 '18 19:03

Tony Scialo


People also ask

What is uppercase pipe in angular?

UpperCasePipelinkTransforms text to all upper case. {{ value_expression | uppercase }}

Which pipe is used to transform text into lowercase?

LowerCasePipe: UpperCasePipe is used to transforms text to lowercase.

What does Titlecase pipe do?

TitleCasePipe is used to Transforms all the text to titlecase.

What data type is returned LowerCasePipe in angular?

Angular lowercase pipe accepts only string types.


1 Answers

This is why:

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" />

If you use a pipe to lowercase, then the value will be lowercase.

So if you aren't using an input field or don't intend on extracting the data from an element, then I would say just to use css - at least then you will only have to define this in 1 place (ideally), compared to having to explicitly use a pipe in all fields which is an extensibility nightmare for larger applications.


If you want to see a working angular example of this, check this question: Using Pipes within ngModel on INPUT Elements in Angular2-View
like image 77
Zze Avatar answered Sep 21 '22 07:09

Zze