Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SimpleChange and SimpleChanges

There are two terms in angular 5 SimpleChange and SimpleChanges, I didn't understand clearly from the official document could someone please explain me ??/

like image 684
Punit Avatar asked Mar 11 '18 13:03

Punit


2 Answers

SimpleChange is a class which is used as a type of all the properties in SimpleChanges interface.

class SimpleChange {
    previousValue: any;
    currentValue: any;
    firstChange: boolean;

    constructor(previousValue: any, currentValue: any, firstChange: boolean)

    isFirstChange(): boolean

}

interface SimpleChanges {
    __index(propName: string): SimpleChange
}
like image 111
patrick.1729 Avatar answered Oct 11 '22 19:10

patrick.1729


SimpleChange class represents a basic change from a previous to new value.

It has following properties.

previousValue: Keeps previous value of input property.

currentValue: Keeps current value of input property.

isFirstChange(): Boolean value that tells whether the new value is the first value assigned.

https://angular.io/api/core/SimpleChange

SimpleChanges is the interface that represents all input changes as object for a component. SimpleChanges has the key as input property names and values are the instances of SimpleChange class.

e.g: 
@input() id: number;
@input() name: string;
ngOnChanges(changes: SimpleChanges) {
  console.log(changes);
}
// Output
{id: SimpleChange, name: SimpleChange}

https://angular.io/api/core/SimpleChanges

Source: https://www.concretepage.com/angular-2/angular-2-4-onchanges-simplechanges-example

like image 20
Api Avatar answered Oct 11 '22 20:10

Api