Created
December 17, 2016 19:20
-
-
Save wKoza/b335fa61e8a152ad1f42d624f8ea34db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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