Search code examples
outputngrxangular7event-propagationangular-event-emitter

@ngrx Angular 6/7 emitting object through components


i'm using angular 7 with @ngrx.
I've reproduced the issue i'm having on stackblitz, here is the link

If you check the console, after clicking on the active/Unactive checkbox, you'll see that in the child component (supplier-card-item.component) the model is being updated correctly but when being emitted to the parent component (supplier-card-list.component), the object is restored to its original value which is the one stored in the state container.

Store's actions, effects, reducers, etc... are in the root-store folder.

Thank you for your help


Solution

  • Problem is with what you are emitting back((child_hasChange)="onSupplierUpdate($event)")

            <app-supplier-card-item *ngFor="let supplier of suppliersActive" 
            [supplier]="supplier"
            (child_hasChange)="onSupplierUpdate($event)" <<- here
            ></app-supplier-card-item>
        </mat-tab>
    
        <mat-tab label="Inactive">
            <app-supplier-card-item *ngFor="let supplier of suppliersUnactive" 
            [supplier]="supplier"
            (child_hasChange)="onSupplierUpdate($event)" <<- here
            ></app-supplier-card-item>
        </mat-tab>
    </mat-tab-group>