mercredi 8 février 2017

Set object properties in TypeScript with setters and getters

Vote count: 0

How do you set each property of an object with a setter in TypeScript?

export class AuthService {
    private _user:User; // User is my model

    constructor(...){}

    public get user()
    {
        return this._user;
    }

    public set user(value){
        this._user = value;
    }
...

Then setting anywhere gives errors when:

this.authService.user.id = data.userId;
this.authService.user.isLoggedIn = 'true';

asked 28 secs ago

Let's block ads! (Why?)



Set object properties in TypeScript with setters and getters

Aucun commentaire:

Enregistrer un commentaire