Bartosz
Bartosz

Reputation: 4592

changing value of ko.observable

I have a ko.observable property of an object called "totalLength". While using application I would like to physically amend new value to this property. How can I do that?

I can preview the value of the demanded property by displaying:

alert(feature.totalLength());

so I know that it is the one. But when I assign a new value to it:

feature.totalLength() = 10;

I get an error:

ReferenceError: invalid assignment left-hand side

Why?

Upvotes: 27

Views: 28504

Answers (2)

sellmeadog
sellmeadog

Reputation: 7517

ko.observable is a function so you need to set the value like this feature.totalLength(10).

Upvotes: 50

bjornd
bjornd

Reputation: 22933

You can change value of observable like this:

feature.totalLength(10)

Upvotes: 15

Related Questions