Currently, I am developing a TypeScript-powered Angular (5) application and I have encountered a puzzling question that is proving elusive to solve. Let me illustrate with the following example:
...
export class SomeComponent implements onInit {
...
// Properties
someProperty: string = null;
isValid: boolean = this.someProperty !== null;
...
}
In this scenario, the isValid
variable will be initially set to false
since someProperty === null
upon initialization. My goal is for isValid
to dynamically update whenever someProperty
changes, reflecting the appropriate boolean value based on whether or not someProperty
is null.
Having familiarity with React and its state management system in the past, I incorrectly assumed that the above approach would work seamlessly. However, it seems that it doesn't, leaving me pondering about the proper TypeScript methodology for achieving this desired functionality?