Ilya
Ilya

Reputation: 29693

knockout.js bind string value to function

JSFiddle source
I use hello.bind('Hi!!!')
but inside method hello i get view-model Object instead of string value. Any ideas why?

Upvotes: 0

Views: 263

Answers (1)

Justin Helgerson
Justin Helgerson

Reputation: 25521

Change your markup to:

<button data-bind="click: hello.bind($data, 'Hi!!!')">Say hello</button>

From the documentation:

Alternatively, if you prefer to avoid the function literal in your view, you can use the bind function, which attaches specific parameter values to a function reference. More on bind can be found at Mozilla.

Upvotes: 1

Related Questions