Detecting Change on Observable Property or Model

137 views
Skip to first unread message

Eqbal sohrabi

unread,
Mar 15, 2021, 1:33:22 AM3/15/21
to KnockoutJS
I want to track change on view-model or an observable item, and run some other function when model changed. I don't want to bind change event to my html elements.
Sample:
var myModel={
    myProp:ko.observable(),
  myFunc() {
      alert("myProp changed");
    }
}

Jonathan Shay

unread,
Mar 15, 2021, 7:03:05 AM3/15/21
to knock...@googlegroups.com
You want to use a kocomputed observable. They update anytime one of the properties to which they refer are updated.

jks...@jkshay.com

unread,
Mar 15, 2021, 7:25:45 AM3/15/21
to knock...@googlegroups.com
Alternatively you could subscribe to changes in an observable with the observableProperty.subscribe function.

On Mar 15, 2021 7:01 AM, Jonathan Shay <jks...@jkshay.com> wrote:
You want to use a ko.computed observable. They update anytime one of the properties to which they refer are updated.


Didier Gasser-Morlay

unread,
Mar 15, 2021, 11:24:54 AM3/15/21
to knock...@googlegroups.com
Or subscribe on the observable

Le lun. 15 mars 2021 à 12:03, Jonathan Shay <jks...@jkshay.com> a écrit :
You want to use a kocomputed observable. They update anytime one of the properties to which they refer are updated.

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knockoutjs/DD98DB1A-D722-B44E-A897-A1B6A6D676BE%40hxcore.ol.

Eqbal sohrabi

unread,
Apr 14, 2021, 10:28:42 AM4/14/21
to KnockoutJS

I Just using  observableProperty.subscribe and the problem resolved.
Reply all
Reply to author
Forward
0 new messages