4

I'm using ngOnChanges for to detect de current value and previous value of "idCopiadora" property. When i asked for de currectValue always return de current value, that is ok but the previous value always returns undefined I can not see what is wrong, help please.

component father .html:

<app-gestioncopiadora-ficha *ngIf="selectedId !== 0" [idCopiadora] ="selectedId" (onClosed)="closeModal($event)"></app-gestioncopiadora-ficha>
<div [class] = "selectedId === 0? '':'hide'">
    <div style="display:table;width:100%" class="listadoTabla" [@fadeInAnimation]="animationEnabled" (@fadeInAnimation.done)="animationEnabled = false">
        <div *ngFor="let fila of tempRows" style="display:inline-block; width:100%;" class="listadoFila project-view-item" (click)="selectFila(fila.Id)">
            <div *ngIf="fila" style="width:100%;">
                <div style="display:inline-block;padding-left: 5px;">
                    <i class="glyphicon glyphicon-chevron-down"></i>
                </div>
                <div style="display:inline-block;width:25%;padding-left: 5px;">
                    <span *ngIf="fila.CodigoCopiadora">{{fila.CodigoCopiadora}} - </span>
                    <span class="negrita600">{{fila.Marca}}</span>
                    <span class="negrita600">{{fila.Modelo}}</span>       
                </div>
            </div>
        </div>
    </div>
</div>

component father .ts:

//... someStuf:
selectFila(_id: any) {
    this.selectedId = _id;       
}

component child:

import { Component, OnDestroy, OnInit, SimpleChanges, Input, OnChanges, 
SimpleChange } from '@angular/core';
@Component({
    selector: 'app-gestioncopiadora-ficha',
    template: `{{idCopiadora}}`,
    styleUrls: ['./cuerpo.component.css'],
    inputs: ["idCopiadora"],
})
export class CuerpoComponent implements OnChanges {
    constructor() {       
    }
     @Input() idCopiadora: number;

     ngOnChanges(changes: SimpleChanges ) {
        for (let propertyName in changes) {
            let change = changes[propertyName];
            let current = JSON.stringify(change.currentValue);
            let previous = JSON.stringify(change.previousValue);
            console.log('prev value: ', current);
            console.log('got name: ', previous);
        }
    }
}
ararb78
  • 1,137
  • 5
  • 19
  • 44

0 Answers0