import { bootstrapApplication } from '@angular/platform-browser';
import { Component, Pipe } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
@Pipe({ name: 'titlecase2', standalone: true })
export class TitleCase2Pipe {
transform(value) {
if (!value) return '';
return String(value)
.split(/\s+/)
.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
.join(' ');
}
}
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule, FormsModule, TitleCase2Pipe],
template: `
<h3>Custom Pipe</h3>
<label>
Text: <input [(ngModel)]="text" placeholder="type here" />
</label>
<p>Original: {{ text }}</p>
<p>TitleCase2: {{ text | titlecase2 }}</p>
`
})
export class App {
text = 'hello angular pipes';
}
bootstrapApplication(App);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Angular Custom Pipe</title>
</head>
<body>
<app-root></app-root>
</body>
</html>