Currently, I am attempting to trigger an update in a computed property from my viewmodel to the UI. However, I am only able to retrieve the initial value and not any subsequent values. When trying to modify the property, it fails due to it not being recognized as a function.
Here's a glimpse of the site:
<script src="../../libraries/knockout-3.4.1.js"></script>
<input id="nameInput" data-bind="value: processName" type="text"/>
<input id="nodetotalInput" data-bind="value: processNodeCount" type="text"/>
Now let's take a look at the View Model:
export class ProcessViewModel {
public processName: KnockoutObservable<string>;
public processNodeCount: KnockoutObservable<number>;
constructor() {
try {
this.testService = new Test.TestService();
this.setBindings();
}
catch (e) {
console.log(e);
}
}
public setBindings(): void {
this.processName = ko.computed<string>(
function() { processViewModel.isLoaded() ? processViewModel.testService.flowModel.process.name : ""; }
);
this.processNodeCount = ko.computed<number>(
function() { processViewModel.isLoaded() ? processViewModel.testModel.nodeCount() : 0; }
);
}
public isLoaded(): boolean {
return this.testService.isLoaded();
}
public refreshProcessDetails() {
try {
let message: string = "IsLoaded" + this.isLoaded();
console.log(message);
/** attempts at triggering an update */
this.processName();
this.processName.valueHasMutated(); // fails because it's not a function
this.processNodeCount();
}
catch (e) {
console.log(e);
}
}
}
And here's how it's bound:
declare var processViewModel: Process.ProcessViewModel;
window.onload = () => {
processViewModel = new Process.ProcessViewModel();
processViewModel.setBindings();
ko.applyBindings(processViewModel);
}
An error occurs when calling
this.processName.valueHasMutated()
within this.refreshProcessDetails()
:
stack:"TypeError: this.processName.valueHasMutated is not a function\n at