Angular 4 introduced a new 'titlecase' pipe '|' and use to changes the first letter of each word into the uppercase.
The example as,
<h2>{{ 'ramesh rajendran` | titlecase }}</h2> <!-- OUTPUT - It will display 'Ramesh Rajendran' -->
Is it possible in typescript code? And How?
TitleCasePipelinkCapitalizes the first letter of each word and transforms the rest of the word to lower case. Words are delimited by any whitespace character, such as a space, tab, or line-feed character. {{ value_expression | titlecase }}
The titlecase pipe is used to transform first character of the word to capital and rest word to lower case. Words are delimited by any white space character, such as a space, tab, or line-feed character.
Yes it is possible in TypeScript code. You'll need to call the Pipe's transform() method. You'll need to add TitleCasePipe in yout AppModule providers. You can call the transformation on button click or some other event in the typescript code.
Angular UpperCasePipe transforms string to uppercase and LowerCasePipe transforms string to lowercase. It is used as follows. UpperCasePipe uses uppercase keyword to transform string into uppercase as given below. {{message | uppercase}} Here message is a component property.
Yes it is possible in TypeScript code. You'll need to call the Pipe's transform()
method.
Your template:
<h2>{{ fullName }}</h2>
In your .ts:
import { TitleCasePipe } from '@angular/common'; export class App { fullName: string = 'ramesh rajendran'; constructor(private titlecasePipe:TitleCasePipe ) { } transformName(){ this.fullName = this.titlecasePipe.transform(this.fullName); } }
You'll need to add TitleCasePipe
in yout AppModule providers. You can call the transformation on button click or some other event in the typescript code.
Here is a link to PLUNKER DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With