How to subscribe to an expression when passing param in custom binding handler....

36 views
Skip to first unread message

kellykinsellives

unread,
Jul 18, 2017, 7:13:50 PM7/18/17
to KnockoutJS
Hi.

  I am writing a custom binding handler and I am passing a parameter called 'disabled'. I expect this to be an observable so I can subscribe to it, but I see that users could pass an expression if they want. For example

<input data-bind="mytext: { disabled: !isEditable() }">

My problem is I am only getting the evaluated value of !isEditable() in the binding handler. I need to know whenever the expression changes though. I read that knockout can make a computed observable from an expression.

Is there a way I can get an observable on the passed in expression itself rather than the expression value?

Thank you,
Kelly

noirabys

unread,
Jul 19, 2017, 10:02:28 AM7/19/17
to KnockoutJS
it's realy simple, access the disabled property wihtin the init method which will register the dependency in knockout,
after that the update method will be automatically triggered up on change of the expression
 noirabys

kellykinsellives

unread,
Jul 20, 2017, 8:52:02 PM7/20/17
to KnockoutJS
It worked perfectly. Thank you very much!
Reply all
Reply to author
Forward
0 new messages