transform(value:string): string {
let first = value.substr(0,1).toUpperCase();
return first + value.substr(1);
}
content_copy
@Component({
selector: 'titlecase-pipe',
template: `<div>
<p>{{'some string' | titlecase}}</p> <!-- output is expected to be "Some String" -->
<p>{{'tHIs is mIXeD CaSe' | titlecase}}</p> <!-- output is expected to be "This Is Mixed Case" -->
<p>{{'it's non-trivial question' | titlecase}}</p> <!-- output is expected to be "It's Non-trivial Question" -->
<p>{{'one,two,three' | titlecase}}</p> <!-- output is expected to be "One,two,three" -->
<p>{{'true|false' | titlecase}}</p> <!-- output is expected to be "True|false" -->
<p>{{'foo-vs-bar' | titlecase}}</p> <!-- output is expected to be "Foo-vs-bar" -->
</div>`
})
export class TitleCasePipeComponent {
}
app.filter('capitalize', function() {
return function(token) {
return token.charAt(0).toUpperCase() + token.slice(1);
}
});