Reputation: 523
I'm having trouble getting Knockout to update the value of my observable.
Model:
function AppViewModel() {
var self = this;
self.observable = ko.observable();
self.test = function() {
self.observable("test")
}
};
var model = new AppViewModel();
ko.applyBindings(model);
View:
<p>Value of observable: <input data-bind="value: $root.observable()" /></p>
<p>The value is: <span data-bind="text: $root.observable()"></span></p>
When I type text into the input field, it should update the value of my observable to what I've typed, correct? But the 2nd paragraph doesn't update its text accordingly.
Thanks!
Upvotes: 0
Views: 1587
Reputation: 134841
Remove the parentheses in your bindings. You want to bind to the observable itself, not the value the observable is holding.
<p>Value of observable: <input data-bind="value: $root.observable" /></p>
<p>The value is: <span data-bind="text: $root.observable"></span></p>
Upvotes: 4