Commit a7f74ad2 by Emile TAVERNE

Ajout pipe capitalize

parent 4e946eef
......@@ -6,6 +6,7 @@ import {AppComponent} from './app.component';
import * as Components from './components';
import * as Services from './services';
import * as Pipes from './pipes';
@NgModule({
declarations: [
......@@ -14,6 +15,7 @@ import * as Services from './services';
Components.LoaderComponent,
Components.PageTrombinoscopeComponent,
Components.TrombinoscopeCardComponent,
Pipes.CapitalizePipe,
],
imports: [
BrowserModule,
......
<div *ngIf="person" class="card">
<h2 bp="text-center">{{ person.fullName }}</h2>
<h2 bp="text-center">{{ person.fullName | capitalize }}</h2>
<img [src]="person.image">
</div>
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'capitalize'})
export class CapitalizePipe implements PipeTransform {
transform(value: string): string {
return value
.split(' ')
.reduce((acc: string, part: string) => {
return `${acc ? `${acc} ` : ''}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
}, null);
}
}
export * from './capitalize.pipe';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment