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?
Apr 10, 2025 in Angular by Nidhi
• 16,260 points
• 1,375 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 Apr 10, 2025 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,800 points
• 7,751 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, 2025 in Angular by Kavya
• 1,592 views
0 votes
1 answer

How to make a sequence of http requests in Angular 6 using RxJS

You can utilize the concatMap operator. This ...READ MORE

answered Feb 12, 2025 in Angular by Kavya
• 1,734 views
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 Apr 10, 2025 in Angular by anonymous
• 1,060 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, 2025 in Angular by Nidhi
• 16,260 points
• 1,035 views
0 votes
0 answers

What’s the difference between Observables and Promises?

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

Mar 3, 2025 in Angular by Nidhi
• 16,260 points
• 767 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, 2025 in Angular by Nidhi
• 16,260 points
• 954 views
0 votes
0 answers

When to use switchMap vs concatMap?

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

Mar 3, 2025 in Angular by Nidhi
• 16,260 points
• 1,286 views
0 votes
1 answer
0 votes
0 answers

How to extend a pipe in Angular?

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

Mar 6, 2025 in Angular by Nidhi
• 16,260 points
• 972 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