Cannot write ko.computed if you did not specify the "write" option

I try to use computed properties in other computed properties, and when I run the code, I get the following error in the console.

Cannot write ko.computed if you did not specify the "write" option

 function AppViewModel() { var self = this; self.firstName = ko.observable('rahul'); self.lastName = ko.observable('sharma'); self.fullName = ko.computed(function() { return self.firstName() +' ' + self.lastName(); }); self.upperFullName = ko.computed(function() { return self.fullName.toUpperCase(); }); } // Activates knockout.js ko.applyBindings(new AppViewModel()); 

and here is the html code and js fiddle link

 <p><input data-bind="value: firstName"></p> <p><input data-bind="value: lastName"></p> <p><input data-bind="value: fullName"></p> <p> <span data-bind="text: upperFullName"> </span> </p> 
+8
computed-observable
source share
1 answer

self.fullName is a function that returns a computed value.

 self.upperFullName = ko.computed(function() { return self.fullName().toUpperCase(); }); 

pay attention to the brackets!

+8
source share

All Articles