简体   繁体   中英

Angular2 LifecycleEvent.onChange Not Firing

As of this writing, Im using Angular 2.0.0-alpha.36. In the following code, everything functions as expected, EXCEPT for the onChange:

/// <reference path="../../typings-custom/_custom.d.ts" />

import {Component, View, LifecycleEvent} from 'angular2/angular2';

@Component({
    selector: 'counter',
    lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onChange, LifecycleEvent.onCheck, LifecycleEvent.onAllChangesDone]
})
@View({
    template: '<button (click)="increment()">Increase Component {{count}}</button>'
})

export class Counter {

    count: number = NaN;

    constructor()
    {
        this.count = 0;
    }

    increment()
    {
        ++this.count;
    }

    onInit()
    {
        console.log('onInit');
    }

    onCheck()
    {
        console.log('onCheck');
    }

    onChange(changes)
    {
        console.log('onChange');
        console.log(changes);
    }

    onAllChangesDone()
    {
        console.log('onAllChangesDone');
    }
}

Aside from numerous Stack Overflow searches, I've referenced several threads including:

http://plnkr.co/edit/gtfY4C5mXJDhohEIVkSn?p=preview

http://learnangular2.com/lifecycle/

Any help would be appreciated.

onChange() gets triggered when there are changes in a component input bindings.

The problem is that the Counter component does not have input properties (input bindings), so that's why the on onChange() event is never called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM