1

I'm trying to push values into the array from the other component with no relation(Parent or child), but after coming back to my current component where array values are already updated but no change on DOM. ngOnInit isn't called because the component is already launched. I wanted to update the DOM as well without any event from the other component. Here is the add-family component where I want the change

<ng-container *ngFor="let i of currentFilesRV">
              <ion-icon *ngIf="i === control.key" (click)="alreadySubmitted()" class="icon-dyamic" name="checkmark-circle" style="color: green;"></ion-icon>
            </ng-container>

now check the array which is updated by the other component which is add-sample component

this.addFamilyComponent.currentFamilyFiles(this.relationValue);

also the change in array in add-family component(which is working)

currentFamilyFiles(relationVal){
      this.zone.run(() => {
        this.currentFilesRV.push(relationVal)
        console.log("RV: ", this.currentFilesRV)
      })
  }

i've used this ngZone from here Router Navigate does not call ngOnInit when same page

Faraz Khan
  • 121
  • 1
  • 1
  • 5
  • You should NEVER use change detection manually. You don't need to do all of this to get a value from another component. Just use a service and add a variable that will be able to hold the value. And just call that variable In Component A or B. – StackoverBlows Dec 05 '22 at 15:28
  • 1
    uh, Thanks alot, it worked, @StackoverBlows, you saved my day, I wasn't using the service before, but its working perfectly now, thanks to you again! – Faraz Khan Dec 06 '22 at 07:26

0 Answers0