Property change subscription with Aurelia

前端 未结 4 1569
栀梦
栀梦 2020-11-30 04:03

I have a property on my viewmodel which I want to listen to and trigger events based on its value, like this:

class viewModel {
  constructor() {
    this.va         


        
4条回答
  •  -上瘾入骨i
    2020-11-30 04:18

    listen to and trigger events based on its value

    A snippet from code using TypeScript, hopefully that will get you an idea:

    import {bindingMode} from "aurelia-binding";
    
    export class Example{
    
        @bindable
        public description: string;
    
        private descriptionChanged(newValue: string, oldValue: string): void {
            console.log(newValue, oldValue);
        }
    }
    

    Method name should follow convention `${propertyName}Changed`


    EDIT: That's exactly what Decade Moon suggested in the comment above: Property change subscription with Aurelia

提交回复
热议问题