Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import {Component, Input} from '@angular/core';
@Component({
selector: 'person',
template: '<h1>{{person.name}} {{person.lastname}}</h1>'
})
export class PersonComponent {
private _person: any
@Input()
set person(person: any){
if (person && person.hasOwnProperty('name')) {
person.name=this.capitalizeFirstLetter(person.name);
}
this._person=person;
}
get person():any{
if (this._person && this._person.hasOwnProperty('lastname')) {
this._person.lastname=this.capitalizeFirstLetter(this._person.lastname);
}
return this._person;
}
private capitalizeFirstLetter(word: string):string {
return word.charAt(0).toUpperCase() + word.slice(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment