''',
styles: const [
'.counter {background: LightYellow; padding: 8px; margin-top: 8px}'
],
directives: const [Spy])
class MyCounter implements OnChanges {
@Input() num counter;
List changeLog = [];
ngOnChanges(Map changes) {
// Empty the changeLog whenever counter goes to zero
// hint: this is a way to respond programmatically to external value changes.
if (this.counter == 0) {
changeLog.clear();
}
// A change to `counter` is the only change we care about
SimpleChange prop = changes['counter'];
var prev = prop.isFirstChange() ? "{}" : prop.previousValue;
changeLog.add(
'counter: currentValue = ${prop.currentValue}, previousValue = $prev');
}
}
@Component(
selector: 'counter-parent',
template: '''