Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import { Component, Input, OnChanges, SimpleChange } from '@angular/core';
selector: 'version-child',
template: `
<h3>Version {{major}}.{{minor}}</h3>
<h4>Change log:</h4>
<li *ngFor="let change of changeLog">{{change}}</li>
export class VersionChildComponent implements OnChanges {
@Input() major: number;
@Input() minor: number;
changeLog: string[] = [];
ngOnChanges(changes: {[propKey: string]: SimpleChange}) {
let log: string[] = [];
for (let propName in changes) {
let changedProp = changes[propName];
let from = JSON.stringify(changedProp.previousValue);
let to = JSON.stringify(changedProp.currentValue);
log.push( `${propName} changed from ${from} to ${to}`);
this.changeLog.push(log.join(', '));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment