Detect changes to model state – Aurelia

In order to intercept or subscribe to changes in your model, you need to decorate the properties you’re interested in with observable and implement the convention based <propertyName>Changed function:

import {observable} from 'aurelia-framework';

export class Todo {
  @observable done = false;
  description = '';

  doneChanged(newVal, oldVal) {
    console.log(`done change from ${oldVal} to ${newVal}`);
  }
}

 

One thought on “Detect changes to model state – Aurelia

Comments are closed.