0

I have a service which holds some data:

@Injectable()
export class DataService {
  data = {
    a: [
      {label: 'label 1', checked: true},
      {label: 'label 2', checked: true},
      {label: 'label 3', checked: true}
    ]
  }
}

and a component that imports the service and uses data from data.a to generate checkboxes (with checked property indicating the initial state of each checkbox). After user checks and unchecks boxes, values in DataService are automatically updated by angular.

There is another service StorageService which also injects DataService and is supposed to store data.a to browser's local storage automatically every time a checked property is changed. What I can't figure out is how to observe those changes for individual object properties which are nested deeply like so?

1 Answer 1

0

a is some array of something? Array, Interface?

In your service StorageService you can access data througt

constructor(private _dataService : DataService  ){}

console.log(this._dataService.data.a[0].label);

Post more some code if this not working for you.

Sign up to request clarification or add additional context in comments.

2 Comments

a is just an array of objects. It's static data. I can access the data in StorageService but what I need it to do is to subscribe to it to detect any changes of data. I presume I should make data object observable (perhaps rxjs BehaviorSubject) but I can't figure out how to make it work on such object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.