LazyDay
10/9/2017 - 7:48 PM

Angular getter setter

import { Component, Input } from '@angular/core';

@Component({
    moduleId: module.id,
    template: '{{fullName}}',
    selector: 'app-card',
})
export class CardComponent {
    private _firstName: string;
    private _lastName: string;

    @Input('firstName')
    set firstName(value){
        this._firstName = value;
    }

    get firstName(){
        return this._firstName;
    }

    @Input('lastName')
    set lastName(value){
        this._lastName = value;
    }

    get lastName(){
        return this._lastName;
    }

    get fullName(){
        return this._lastName + ' ' + this._firstName;
    }
}
<app-card firstName="Danya" [lastName]="'Ivanov'"></app-card>
import { Component } from '@angular/core';

@Component({
    moduleId: module.id,
    templateUrl: 'card-host.component.html'
})
export class CardHostComponent {
}