0

Im looking for the best approach for a complex object change detection that is a property of a service.

example Updated:

export interface EngineType{
    isGas: false,
    isElectric: false,
    liters: 6
    cyclinders:6
}

export class CarService {
    engine: EngineType
}

export class HondaService {

    constructor(carService: CarService){}

    carService.engine.isGas = true;  // How can this change be detected?

}

I have alot of simple type properties on CarService that I would rather not apply getters and setters for each one.

thanks in advance.

Jambione
  • 21
  • 2
  • I cannot imagine why you would need this.. however, Observables would probably make things easier? – MikeOne Jul 12 '22 at 17:13
  • Are you suggesting Observables will trigger change detection for an update of a nested property on an services object? – Jambione Jul 12 '22 at 17:32
  • @Jambione Let's assume you are going to use this complex object in the HTML, when you update the service properties, it will update in html automatically, change detection is automatic is my point! – Naren Murali Jul 12 '22 at 17:59
  • Have you seen this https://stackoverflow.com/questions/45450942/how-can-i-detect-when-a-property-changes-on-a-service – Kaneki21 Jul 12 '22 at 18:04
  • When you say "change detected", what do you mean? What do you want to happen when they change? – Chris Hamilton Jul 12 '22 at 22:34
  • @ChrisHamilton I would like to know when a change occurs so I can call a function. My issue with observables are, we need to explicitly call NEXT to update values on subscribers. I want to implicitly trigger an update when changing the property value. – Jambione Jul 13 '22 at 10:24
  • Check out these threads: https://stackoverflow.com/a/50862441/12914833, https://stackoverflow.com/q/1063813/12914833 – Chris Hamilton Jul 13 '22 at 12:16
  • This answer is a great solution as well: https://stackoverflow.com/a/10638860/12914833 – Chris Hamilton Jul 13 '22 at 13:11

0 Answers0