2

I have an object as follows which comes through @Input.

@Input() data;
//**
{
  "class_a":["John","Harr y"],
  "class_b":["Joseph","Phlip","David"],
  "class_c":[]
}  
**//

I need to detect the changes if data added or removed in class_a or class_b but im only getting change detection if values of objects are string. Since the keys in my object are dynamic i couldn't iterate the object and create Iterable differs. Is there anyway to detect changes of array inside the object.

My Implementation:

constructor(private differs: KeyValueDiffers) {
      this.keyValueDiffer = differs.find({}).create();
}

ngDoCheck() {
    let changes = this.keyValueDiffer.diff(this.data[this.component.factedBindKey]);
    if (changes) {
        console.log('Changes detected');
    }
}
Tom
  • 183
  • 1
  • 1
  • 9

1 Answers1

0

you can test like this

constructor(private cd: ChangeDetectorRef) {
}
  
ngOnChanges() {
    let actualData =this.data
    this.mymethod(actualData);
}

and call this line where you want to access that actual data like this

mymethod(data){
this.cd.detach();
//write main logic 
}
Zubair Saif
  • 1,106
  • 1
  • 14
  • 29