Skip to content

Instantly share code, notes, and snippets.

@rezanid
Created November 26, 2020 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezanid/5040d21c2d300781d3b80a2ea3e85c0a to your computer and use it in GitHub Desktop.
Save rezanid/5040d21c2d300781d3b80a2ea3e85c0a to your computer and use it in GitHub Desktop.
How to define a computed property in ViewModel, KnockoutJS, TypeScript
module SampleModule {
export class SampleComponent {
isValid: KnockoutComputed<boolean>;
//...
constructor(public element) {
//...
this.isValidConnectAs = ko.computed<boolean>({
owner: this,
read: () => {
return this.connectAs().duser().length === 7;
}
});
ko.applyBindings(this, element);
}
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment