Punit
Punit

Reputation: 301

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 ??/

Upvotes: 13

Views: 15284

Answers (2)

patrick.1729
patrick.1729

Reputation: 4402

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
}

Upvotes: 1

Api
Api

Reputation: 1841

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

Upvotes: 9

Related Questions