SaiBand
SaiBand

Reputation: 5355

How to get handle on Old Value in Knockout using CoffeeScript

I am using Knockout in conjunction with CoffeeScript. I have a variable called SalesStage.ID which is an observable. I need get the old value, oldVal, how do I get it?

This is what I tried:

this.data.SalesStage.ID().subscribeChanged((newVal, oldVal)=> 
    console.log (oldVal) console.log(newVal))

And this is the following error:

cannot call method subscribeChanged of null.

Any ideas and suggestions are greatly appreciated.

Upvotes: 0

Views: 104

Answers (1)

Robert Westerlund
Robert Westerlund

Reputation: 4838

In plain javascript you could subscribe to the old value when the value changes with the following code:

this.data.SalesStage.ID.subscribe(function (oldValue) { 
    console.log(oldValue); 
}, null, 'beforeChange');

You can read more about it on the KnockoutJS documentation page on Observables.

Upvotes: 1

Related Questions