0

I have simple class which looks like this:

export class MessagesPage  {

    @ViewChild(Content) content: Content;

    public message  = '';
    public messages = [];

    public state = 'general';
}

Is it possible inside the class to detect if state property is changed?

1 Answer 1

5

Make them getters and setters. There is no other way to get notified about changes:

export class MessagesPage  {

    @ViewChild(Content) content: Content;

    public message  = '';
    public messages = [];

    private _state = 'general';
    public get state() { return this._state; }
    public set state(value:string) { 
      this._state = value;
      console.log('state changed', this._state);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.