I have an object of type Person which has fields of firstName, lastName, age. I detect for any change using Behavior Subject. I have an observing component that is subscribed to every change on this Person Object. Once the change detects the observing component will call a method. I want this method to change the property of the Observable Person Object.
In My Service
export class PersonService {
personToCopySource = new BehaviorSubject<Person>(null);
personToCopy = this.personToCopySource.asObservable();
In My Component
export class ObservingComponent {
constructor(public person: Person) {}
ngOnInit(){
this.personService.person.subscribe(
data=> {
this.updateMethod()
}
)
}
updateMethod(){
this.personService.firstName = 'updated First Name';
}
When I change the property of the Observing object I'm getting this error. "Property" firstName does not exist on type Observable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With