Skip to main content

Posts

Showing posts from February, 2019

Angular 7 Pipes - Capitalize a String using TitleCasePipe

Transforms text to title case. Capitalizes the first letter of each word of a string, and transforms the rest of the word to lower case. Syntax looks like:   TitleCasePipe :      {{ expression | titlecase }}   LowerCasePipe : {{ expression | lowercase }}   UpperCasePip :     {{ expression | uppercase }} It looks like : < p > {{'hello anil' | titlecase}} </ p > <!-- output will be "Hello Anil" --> < p > {{'Hello Anil' | lowercase}} </ p > <!-- output will be "hello anil" --> < p > {{'hello anil' | uppercase}} </ p > <!-- output will be "HELLO ANIL" --> Useful Built-in Pipes in Angular 7 or Above: 1.       Async Pipe 2.       C urrency Pipe 3.       Date Pipe 4.       Slice Pipe 5.       Decimal Pipe 6.     ...

Capitalize the first letter of each word of a given string in JavaScript

How do make the first letter of a string uppercase in JavaScript? How to capitalize the first letter of each word of a given string in JavaScript? JavaScript offers different ways to capitalize the first letter of each word of a given string. Let’s see the example for Capitalize the first letter of each word:- //CAPITALIZE THE FIRST LETTER OF EACH WORD OF A GIVEN STRING var capitalize = function ( string ) {   if ( string !== undefined && string . length > 0 ) {       var splitStr = string . split ( " " );       for ( var i = 0 ; i < splitStr . length ; i ++) {           var j = splitStr [ i ]. charAt ( 0 ). toUpperCase ();           splitStr [ i ] = j + splitStr [ i ]. substr ( 1 ). toLowerCase ();       }       return splitStr . join ...

Angular 7 Date Formats using Angular DatePipe | Pre-defined formats

How to format date using DatePipe in Component ofAngular 7? How to Convert Current Date to YYYY-MM-DD format with angular 7? DatePipe - Formats a date value according to locale rules.   For Updating date format we are using DatePipe  from ' @angular/common ' and then use the below code. You have to pass locale string as an argument to DatePipe .   var ddMMyyyy = this . datePipe . transform ( new Date (), "dd-MM-yyyy" ); Pre-defined format options : 1.       'short': equivalent to 'M/d/yy, h:mm a' (6/15/15, 9:03 AM). 2.       'medium': equivalent to 'MMM d, y, h:mm:ss a' (Jun 15, 2015, 9:03:01 AM). 3.       'long': equivalent to 'MMMM d, y, h:mm:ss a z' (June 15, 2015 at 9:03:01 AM GMT+1). 4.       'full': equivalent to 'EEEE, MMMM d, y, h:mm:ss a zzzz' (Monday, June 15, 2015 at 9:03:01 AM GMT+01:00). 5.       'shortDate': equivalent to 'M...