How to implement a pipe that capitalizes the first letter of each word in a string

0 votes
can someone help me with this by including relevant code or example, How to implement a pipe that capitalizes the first letter of each word in a string?
2 days ago in Angular by Nidhi
• 14,600 points
26 views

1 answer to this question.

0 votes

To create a pipe in Angular that capitalizes the initial letter of each word in a string, develop a custom pipe utilizing regular expressions or string manipulation methods.

Capitalize Each Word Pipe

1. Create the Pipe

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({

  name: 'capitalizeWords'

})

export class CapitalizeWordsPipe implements PipeTransform {

  transform(value: string): string {

    if (!value) return '';

    return value.replace(/\b\w/g, char => char.toUpperCase());

  }

}

2. Usage in Template

<p>{{ 'hello world from angular' | capitalizeWords }}</p>

<!-- Output: Hello World From Angular -->

answered 2 days ago by anonymous

Related Questions In Angular

0 votes
1 answer

How to create a URL in the controller .NET MVC?

Hello @kartik, If you just want to get ...READ MORE

answered Jul 23, 2020 in Angular by Niroj
• 82,840 points
6,416 views
0 votes
1 answer

How to change the value of an Observable in TypeScript Angular?

To change the value of an Observable ...READ MORE

answered Feb 21 in Angular by Kavya
155 views
0 votes
1 answer
0 votes
1 answer

How to implement a directive that adds tooltips to form controls dynamically?

Custom Tooltip Directive 1. Create the Directive import { ...READ MORE

answered 2 days ago in Angular by anonymous
18 views
0 votes
0 answers

How do Observables improve API call handling in Angular?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
106 views
0 votes
0 answers

What’s the difference between Observables and Promises?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
76 views
0 votes
0 answers

What type of operation do RxJS operators allow for observables?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
85 views
0 votes
0 answers

When to use switchMap vs concatMap?

With the help of an example, can ...READ MORE

Mar 3 in Angular by Nidhi
• 14,600 points
111 views
0 votes
0 answers

How to extend a pipe in Angular?

Can someone exlpain me with the code ...READ MORE

Mar 6 in Angular by Nidhi
• 14,600 points
72 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP