Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

titlecase pipe in angular 4

Tags:

angular

pipe

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?

like image 223
Ramesh Rajendran Avatar asked Aug 22 '17 12:08

Ramesh Rajendran


People also ask

What is Titlecase in angular?

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 }}

What does Titlecase pipe do?

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.

How do you use a title case pipe in typescript?

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.

What is uppercase pipe in angular?

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.


1 Answers

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

like image 127
Faisal Avatar answered Sep 18 '22 17:09

Faisal